}
// Creates a new anonymous reference if cobj=NULL or id=0
-void ScriptApiBase::objectrefGetOrCreate(
+void ScriptApiBase::objectrefGetOrCreate(lua_State *L,
ServerActiveObject *cobj)
{
- lua_State *L = getStack();
-
if(cobj == NULL || cobj->getId() == 0){
ObjectRef::create(L, cobj);
} else {
- objectrefGet(cobj->getId());
+ objectrefGet(L, cobj->getId());
}
}
-void ScriptApiBase::objectrefGet(u16 id)
+void ScriptApiBase::objectrefGet(lua_State *L, u16 id)
{
- lua_State *L = getStack();
-
// Get core.object_refs[i]
lua_getglobal(L, "core");
lua_getfield(L, -1, "object_refs");
lua_remove(L, -2); // object_refs
lua_remove(L, -2); // core
}
+
GUIEngine* getGuiEngine() { return m_guiengine; }
void setGuiEngine(GUIEngine* guiengine) { m_guiengine = guiengine; }
- void objectrefGetOrCreate(ServerActiveObject *cobj);
- void objectrefGet(u16 id);
+ void objectrefGetOrCreate(lua_State *L, ServerActiveObject *cobj);
+ void objectrefGet(lua_State *L, u16 id);
JMutex m_luastackmutex;
// Stack index of Lua error handler
// Add object reference
// This should be userdata with metatable ObjectRef
- objectrefGet(id);
+ objectrefGet(L, id);
luaL_checktype(L, -1, LUA_TUSERDATA);
if (!luaL_checkudata(L, -1, "ObjectRef"))
luaL_typerror(L, -1, "ObjectRef");
return;
}
luaL_checktype(L, -1, LUA_TFUNCTION);
- lua_pushvalue(L, object); // self
- objectrefGetOrCreate(puncher); // Clicker reference
+ lua_pushvalue(L, object); // self
+ objectrefGetOrCreate(L, puncher); // Clicker reference
lua_pushnumber(L, time_from_last_punch);
push_tool_capabilities(L, *toolcap);
push_v3f(L, dir);
}
luaL_checktype(L, -1, LUA_TFUNCTION);
lua_pushvalue(L, object); // self
- objectrefGetOrCreate(clicker); // Clicker reference
+ objectrefGetOrCreate(L, clicker); // Clicker reference
// Call with 2 arguments, 0 results
if (lua_pcall(L, 2, 0, m_errorhandler))
scriptError();
lua_getfield(L, -1, "registered_playerevents");
// Call callbacks
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
lua_pushstring(L,type.c_str()); // event type
try {
script_run_callbacks(L, 2, RUN_CALLBACKS_MODE_FIRST);
lua_pushstring(L, to_list.c_str()); // to_list
lua_pushinteger(L, to_index + 1); // to_index
lua_pushinteger(L, count); // count
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 7, 1, m_errorhandler))
scriptError();
if(!lua_isnumber(L, -1))
lua_pushstring(L, listname.c_str()); // listname
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 1, m_errorhandler))
scriptError();
if (!lua_isnumber(L, -1))
lua_pushstring(L, listname.c_str()); // listname
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 1, m_errorhandler))
scriptError();
if (!lua_isnumber(L, -1))
lua_pushstring(L, to_list.c_str()); // to_list
lua_pushinteger(L, to_index + 1); // to_index
lua_pushinteger(L, count); // count
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 7, 0, m_errorhandler))
scriptError();
}
lua_pushstring(L, listname.c_str()); // listname
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 0, m_errorhandler))
scriptError();
}
lua_pushstring(L, listname.c_str()); // listname
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 0, m_errorhandler))
scriptError();
}
// Call function
LuaItemStack::create(L, item);
- objectrefGetOrCreate(dropper);
+ objectrefGetOrCreate(L, dropper);
pushFloatPos(L, pos);
if (lua_pcall(L, 3, 1, m_errorhandler))
scriptError();
// Call function
LuaItemStack::create(L, item);
- objectrefGetOrCreate(placer);
+ objectrefGetOrCreate(L, placer);
pushPointedThing(pointed);
if (lua_pcall(L, 3, 1, m_errorhandler))
scriptError();
// Call function
LuaItemStack::create(L, item);
- objectrefGetOrCreate(user);
+ objectrefGetOrCreate(L, user);
pushPointedThing(pointed);
if (lua_pcall(L, 3, 1, m_errorhandler))
scriptError();
lua_getglobal(L, "core");
lua_getfield(L, -1, "on_craft");
LuaItemStack::create(L, item);
- objectrefGetOrCreate(user);
+ objectrefGetOrCreate(L, user);
// Push inventory list
std::vector<ItemStack> items;
lua_getglobal(L, "core");
lua_getfield(L, -1, "craft_predict");
LuaItemStack::create(L, item);
- objectrefGetOrCreate(user);
+ objectrefGetOrCreate(L, user);
//Push inventory list
std::vector<ItemStack> items;
{
lua_pushstring(L, "object");
lua_setfield(L, -2, "type");
- objectrefGet(pointed.object_id);
+ objectrefGet(L, pointed.object_id);
lua_setfield(L, -2, "ref");
}
else
// Call function
push_v3s16(L, p);
pushnode(L, node, ndef);
- objectrefGetOrCreate(puncher);
+ objectrefGetOrCreate(L, puncher);
pushPointedThing(pointed);
if (lua_pcall(L, 4, 0, m_errorhandler))
scriptError();
// Call function
push_v3s16(L, p);
pushnode(L, node, ndef);
- objectrefGetOrCreate(digger);
+ objectrefGetOrCreate(L, digger);
if (lua_pcall(L, 3, 0, m_errorhandler))
scriptError();
return true;
lua_pushlstring(L, value.c_str(), value.size());
lua_settable(L, -3);
}
- objectrefGetOrCreate(sender); // player
+ objectrefGetOrCreate(L, sender); // player
if (lua_pcall(L, 4, 0, m_errorhandler))
scriptError();
}
lua_pushstring(L, to_list.c_str()); // to_list
lua_pushinteger(L, to_index + 1); // to_index
lua_pushinteger(L, count); // count
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 7, 1, m_errorhandler))
scriptError();
if (!lua_isnumber(L, -1))
lua_pushstring(L, listname.c_str()); // listname
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 1, m_errorhandler))
scriptError();
if(!lua_isnumber(L, -1))
lua_pushstring(L, listname.c_str()); // listname
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 1, m_errorhandler))
scriptError();
if (!lua_isnumber(L, -1))
lua_pushstring(L, to_list.c_str()); // to_list
lua_pushinteger(L, to_index + 1); // to_index
lua_pushinteger(L, count); // count
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 7, 0, m_errorhandler))
scriptError();
}
lua_pushstring(L, listname.c_str()); // listname
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 0, m_errorhandler))
scriptError();
}
lua_pushstring(L, listname.c_str()); // listname
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
- objectrefGetOrCreate(player); // player
+ objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 0, m_errorhandler))
scriptError();
}
lua_getglobal(L, "core");
lua_getfield(L, -1, "registered_on_newplayers");
// Call callbacks
- objectrefGetOrCreate(player);
+ objectrefGetOrCreate(L, player);
script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_FIRST);
}
lua_getglobal(L, "core");
lua_getfield(L, -1, "registered_on_dieplayers");
// Call callbacks
- objectrefGetOrCreate(player);
+ objectrefGetOrCreate(L, player);
script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_FIRST);
}
lua_getglobal(L, "core");
lua_getfield(L, -1, "registered_on_respawnplayers");
// Call callbacks
- objectrefGetOrCreate(player);
+ objectrefGetOrCreate(L, player);
script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_OR);
bool positioning_handled_by_some = lua_toboolean(L, -1);
return positioning_handled_by_some;
lua_getglobal(L, "core");
lua_getfield(L, -1, "registered_on_joinplayers");
// Call callbacks
- objectrefGetOrCreate(player);
+ objectrefGetOrCreate(L, player);
script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_FIRST);
}
lua_getglobal(L, "core");
lua_getfield(L, -1, "registered_on_leaveplayers");
// Call callbacks
- objectrefGetOrCreate(player);
+ objectrefGetOrCreate(L, player);
script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_FIRST);
}
lua_getglobal(L, "core");
lua_getfield(L, -1, "registered_on_cheats");
// Call callbacks
- objectrefGetOrCreate(player);
+ objectrefGetOrCreate(L, player);
lua_newtable(L);
lua_pushlstring(L, cheat_type.c_str(), cheat_type.size());
lua_setfield(L, -2, "type");
lua_getfield(L, -1, "registered_on_player_receive_fields");
// Call callbacks
// param 1
- objectrefGetOrCreate(player);
+ objectrefGetOrCreate(L, player);
// param 2
lua_pushstring(L, formname.c_str());
// param 3
if(objectid == 0)
return 0;
// Return ObjectRef
- getScriptApiBase(L)->objectrefGetOrCreate(obj);
+ getScriptApiBase(L)->objectrefGetOrCreate(L, obj);
return 1;
}
return 1;
}
// Put player on stack
- getScriptApiBase(L)->objectrefGetOrCreate(sao);
+ getScriptApiBase(L)->objectrefGetOrCreate(L, sao);
return 1;
}
for(u32 i = 0; iter != ids.end(); iter++) {
ServerActiveObject *obj = env->getActiveObject(*iter);
// Insert object reference into table
- script->objectrefGetOrCreate(obj);
+ script->objectrefGetOrCreate(L, obj);
lua_rawseti(L, -2, ++i);
}
return 1;