int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel) { int mpcontinue = 1; lua_State* l=luacon_ci->l; lua_pushstring(l, "mousefunctions"); lua_rawget(l, LUA_REGISTRYINDEX); if(!lua_istable(l, -1)) { lua_pop(l, 1); lua_newtable(l); lua_pushstring(l, "mousefunctions"); lua_pushvalue(l, -2); lua_rawset(l, LUA_REGISTRYINDEX); } int len = lua_objlen(l, -1); for (int i = 1; i <= len && mpcontinue; i++) { lua_rawgeti(l, -1, i); lua_pushinteger(l, mx); lua_pushinteger(l, my); lua_pushinteger(l, mb); lua_pushinteger(l, event); lua_pushinteger(l, mouse_wheel); int callret = lua_pcall(l, 5, 1, 0); if (callret) { if (!strcmp(luacon_geterror(), "Error: Script not responding")) { ui::Engine::Ref().LastTick(Platform::GetTime()); for (int j = i; j <= len-1; j++) { lua_rawgeti(l, -2, j+1); lua_rawseti(l, -3, j); } lua_pushnil(l); lua_rawseti(l, -3, len); i--; } luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); lua_pop(l, 1); } else { if(!lua_isnoneornil(l, -1)) mpcontinue = lua_toboolean(l, -1); lua_pop(l, 1); } len = lua_objlen(l, -1); } lua_pop(l, 1); return mpcontinue; }
int luacon_keyevent(int key, int modifier, int event) { int kycontinue = 1; lua_State* l=luacon_ci->l; lua_pushstring(l, "keyfunctions"); lua_rawget(l, LUA_REGISTRYINDEX); if(!lua_istable(l, -1)) { lua_pop(l, 1); lua_newtable(l); lua_pushstring(l, "keyfunctions"); lua_pushvalue(l, -2); lua_rawset(l, LUA_REGISTRYINDEX); } int len = lua_objlen(l, -1); for (int i = 1; i <= len && kycontinue; i++) { lua_rawgeti(l, -1, i); lua_pushlstring(l, (const char*)&key, 1); lua_pushinteger(l, key); lua_pushinteger(l, modifier); lua_pushinteger(l, event); int callret = lua_pcall(l, 4, 1, 0); if (callret) { if (!strcmp(luacon_geterror(), "Error: Script not responding")) { ui::Engine::Ref().LastTick(Platform::GetTime()); for (int j = i; j <= len-1; j++) { lua_rawgeti(l, -2, j+1); lua_rawseti(l, -3, j); } lua_pushnil(l); lua_rawseti(l, -3, len); i--; } luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); lua_pop(l, 1); } else { if(!lua_isnoneornil(l, -1)) kycontinue = lua_toboolean(l, -1); lua_pop(l, 1); } len = lua_objlen(l, -1); } lua_pop(l, 1); return kycontinue && shortcuts; }
bool LuaEvents::HandleEvent(LuaScriptInterface *luacon_ci, Event *event, ByteString eventName) { ui::Engine::Ref().LastTick(Platform::GetTime()); bool cont = true; lua_State* l = luacon_ci->l; lua_pushstring(l, eventName.c_str()); lua_rawget(l, LUA_REGISTRYINDEX); if (!lua_istable(l, -1)) { lua_pop(l, 1); lua_newtable(l); lua_pushstring(l, eventName.c_str()); lua_pushvalue(l, -2); lua_rawset(l, LUA_REGISTRYINDEX); } int len = lua_objlen(l, -1); for (int i = 1; i <= len && cont; i++) { lua_rawgeti(l, -1, i); int numArgs = event->PushToStack(l); int callret = lua_pcall(l, numArgs, 1, 0); if (callret) { if (luacon_geterror(luacon_ci) == "Error: Script not responding") { ui::Engine::Ref().LastTick(Platform::GetTime()); for (int j = i; j <= len - 1; j++) { lua_rawgeti(l, -2, j + 1); lua_rawseti(l, -3, j); } lua_pushnil(l); lua_rawseti(l, -3, len); i--; } luacon_ci->Log(CommandInterface::LogError, luacon_geterror(luacon_ci)); lua_pop(l, 1); } else { if (!lua_isnoneornil(l, -1)) cont = lua_toboolean(l, -1); lua_pop(l, 1); } len = lua_objlen(l, -1); } lua_pop(l, 1); return cont; }
int process_command_lua(pixel *vid_buf, char *console, char *console_error) { int commandret; char * tmp_error; char console2[15]; char console3[15]; char console4[15]; char console5[15]; //sprintf(console_error, "%s", console); if (console && strcmp(console, "")!=0 && strncmp(console, " ", 1)!=0) { sscanf(console,"%14s %14s %14s %14s", console2, console3, console4, console5); if (strcmp(console2, "quit")==0) { return -1; } else if(strncmp(console, "!", 1)==0) { return process_command_old(vid_buf, console+1, console_error); } else { commandret = luacon_eval(console); if (commandret){ tmp_error = luacon_geterror(); strncpy(console_error, tmp_error, 254); printf("%s\n", tmp_error); } } } return 1; }
int luacon_graphicsReplacement(GRAPHICS_FUNC_ARGS, int i) { int cache = 0, callret; lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, lua_gr_func[cpart->type]); lua_pushinteger(luacon_ci->l, i); lua_pushinteger(luacon_ci->l, *colr); lua_pushinteger(luacon_ci->l, *colg); lua_pushinteger(luacon_ci->l, *colb); callret = lua_pcall(luacon_ci->l, 4, 10, 0); if (callret) { luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); lua_pop(luacon_ci->l, 1); } else { cache = luaL_optint(luacon_ci->l, -10, 0); *pixel_mode = luaL_optint(luacon_ci->l, -9, *pixel_mode); *cola = luaL_optint(luacon_ci->l, -8, *cola); *colr = luaL_optint(luacon_ci->l, -7, *colr); *colg = luaL_optint(luacon_ci->l, -6, *colg); *colb = luaL_optint(luacon_ci->l, -5, *colb); *firea = luaL_optint(luacon_ci->l, -4, *firea); *firer = luaL_optint(luacon_ci->l, -3, *firer); *fireg = luaL_optint(luacon_ci->l, -2, *fireg); *fireb = luaL_optint(luacon_ci->l, -1, *fireb); lua_pop(luacon_ci->l, 10); } return cache; }
int luacon_step(int mx, int my) { lua_State* l = luacon_ci->l; lua_pushinteger(l, my); lua_pushinteger(l, mx); lua_setfield(l, tptProperties, "mousex"); lua_setfield(l, tptProperties, "mousey"); lua_pushstring(l, "stepfunctions"); lua_rawget(l, LUA_REGISTRYINDEX); if (!lua_istable(l, -1)) { lua_pop(l, 1); lua_newtable(l); lua_pushstring(l, "stepfunctions"); lua_pushvalue(l, -2); lua_rawset(l, LUA_REGISTRYINDEX); } int len = lua_objlen(l, -1); for (int i = 1; i <= len; i++) { lua_rawgeti(l, -1, i); int callret = lua_pcall(l, 0, 0, 0); if (callret) { if (!strcmp(luacon_geterror(), "Error: Script not responding")) { ui::Engine::Ref().LastTick(Platform::GetTime()); for (int j = i; j <= len-1; j++) { lua_rawgeti(l, -2, j+1); lua_rawseti(l, -3, j); } lua_pushnil(l); lua_rawseti(l, -3, len); i--; } luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); lua_pop(l, 1); } len = lua_objlen(l, -1); } lua_pop(l, 1); return 0; }
int luacon_elementReplacement(UPDATE_FUNC_ARGS) { int retval = 0, callret; if (lua_el_func[parts[i].type]) { lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, lua_el_func[parts[i].type]); lua_pushinteger(luacon_ci->l, i); lua_pushinteger(luacon_ci->l, x); lua_pushinteger(luacon_ci->l, y); lua_pushinteger(luacon_ci->l, surround_space); lua_pushinteger(luacon_ci->l, nt); callret = lua_pcall(luacon_ci->l, 5, 1, 0); if (callret) luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); if(lua_isboolean(luacon_ci->l, -1)){ retval = lua_toboolean(luacon_ci->l, -1); } lua_pop(luacon_ci->l, 1); } return retval; }