int LS_jam_evaluaterule(ls_lua_State *L) { LOL lol; int i; LIST *list; int index; int numParams = ls_lua_gettop(L); if (numParams < 1) return 0; if (!ls_lua_isstring(L, 1)) return 0; lol_init(&lol); for (i = 0; i < numParams - 1; ++i) { lol_add(&lol, luahelper_addtolist(L, L0, 2 + i)); } list = evaluate_rule(ls_lua_tostring(L, 1), &lol, L0); lol_free(&lol); ls_lua_newtable(L); index = 1; for (; list; list = list_next(list), ++index) { ls_lua_pushnumber(L, index); ls_lua_pushstring(L, list->string); ls_lua_settable(L, -3); } return 1; }
int LS_jam_expand(ls_lua_State *L) { LIST *list = L0; LISTITEM* item; int index; int numParams = ls_lua_gettop(L); if (numParams < 1 || numParams > 1) return 0; if (!ls_lua_isstring(L, 1)) return 0; { LOL lol; const char* src = ls_lua_tostring(L, 1); lol_init(&lol); list = var_expand(L0, src, src + strlen(src), &lol, 0); } ls_lua_newtable(L); index = 1; for (item = list_first(list); item; item = list_next(item), ++index) { ls_lua_pushnumber(L, index); ls_lua_pushstring(L, list_value(item)); ls_lua_settable(L, -3); } return 1; }
int LS_jam_getvar(ls_lua_State *L) { LIST *list; LISTITEM* item; int index; int numParams = ls_lua_gettop(L); if (numParams < 1 || numParams > 2) return 0; if (!ls_lua_isstring(L, 1)) return 0; if (numParams == 1) { list = var_get(ls_lua_tostring(L, 1)); } else { TARGET *t; if (!ls_lua_isstring(L, 2)) return 0; t = bindtarget(ls_lua_tostring(L, 1)); pushsettings(t->settings); list = var_get(ls_lua_tostring(L, 2)); popsettings(t->settings); } ls_lua_newtable(L); index = 1; for (item = list_first(list); item; item = list_next(item), ++index) { ls_lua_pushnumber(L, index); ls_lua_pushstring(L, list_value(item)); ls_lua_settable(L, -3); } return 1; }
int LS_jam_evaluaterule(ls_lua_State *L) { LOL lol; int i; LIST *list; LISTITEM* item; int index; const char* rule; int numParams = ls_lua_gettop(L); if (numParams < 1) return 0; if (!ls_lua_isstring(L, 1)) return 0; lol_init(&lol); rule = ls_lua_tostring(L, 1); for (i = 0; i < numParams - 1; ++i) { lol_add(&lol, luahelper_addtolist(L, L0, 2 + i)); } list = evaluate_rule(rule, &lol, L0); lol_free(&lol); ls_lua_newtable(L); index = 1; for (item = list_first(list); item; item = list_next(item), ++index) { ls_lua_pushnumber(L, index); ls_lua_pushstring(L, list_value(item)); ls_lua_settable(L, -3); } return 1; }