Add boolean conditionals to lua

personal/stbuehler/wip
Stefan Bühler 14 years ago
parent 0a1f01fa8c
commit a687b03638

@ -148,6 +148,25 @@ static int lua_cond_lvalue_tostring(lua_State *L) {
return 1;
}
static int lua_cond_lvalue_bool(lua_State *L) {
liServer *srv;
liCondition *c;
liConditionLValue *lvalue;
liCompOperator cmpop;
lvalue = lua_get_condition_lvalue(L, 1);
srv = (liServer*) lua_touserdata(L, lua_upvalueindex(1));
cmpop = (liCompOperator) lua_tointeger(L, lua_upvalueindex(2));
c = li_condition_new_bool(srv, lvalue, cmpop == LI_CONFIG_COND_EQ);
if (c) {
li_condition_lvalue_acquire(lvalue);
lua_push_condition(srv, L, c);
return 1;
}
return 0;
}
static int lua_cond_lvalue_cmp(lua_State *L) {
liServer *srv;
GString *sval;
@ -189,6 +208,9 @@ static void lua_push_cond_lvalue_metatable(liServer *srv, lua_State *L) {
lua_mt_register_cmp(srv, L, "lt", lua_cond_lvalue_cmp, LI_CONFIG_COND_LT);
lua_mt_register_cmp(srv, L, "le", lua_cond_lvalue_cmp, LI_CONFIG_COND_LE);
lua_mt_register_cmp(srv, L, "is", lua_cond_lvalue_bool, LI_CONFIG_COND_EQ);
lua_mt_register_cmp(srv, L, "isnot", lua_cond_lvalue_bool, LI_CONFIG_COND_NE);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
}

@ -50,7 +50,7 @@ static int lua_str_hash_index(lua_State *L) {
wrapper = (LuaWrapper)(intptr_t) lua_touserdata(L, -1); lua_pop(L, 1);
if (!lua_isstring(L, 2) || !ht || !wrapper) {
lua_pop(L, lua_gettop(L));
lua_pushstring(L, "lookup failed");
lua_pushstring(L, "lookup failed (lua_str_hash_index)");
lua_error(L);
return 0;
}
@ -94,7 +94,7 @@ static int lua_str_hash_call(lua_State *L) {
lua_pushstring(L, "__key"); lua_rawget(L, 1);
key = luaL_checklstring(L, -1, NULL);
/* TRACE(srv, "str hash call: '%s'", key); */
/* DEBUG(srv, "str hash call: '%s'", key); */
if (key && NULL != (d = g_hash_table_lookup(ht, key))) {
lua_pop(L, 1);
@ -102,7 +102,10 @@ static int lua_str_hash_call(lua_State *L) {
}
lua_pop(L, lua_gettop(L));
lua_pushstring(L, "lookup failed");
lua_pushstring(L, "lookup '");
lua_pushstring(L, key);
lua_pushstring(L, "' failed (lua_str_hash_call)");
lua_concat(L, 3);
lua_error(L);
return 0;
}

Loading…
Cancel
Save