1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Minor script api fixes/cleanups

This commit is contained in:
sfan5 2022-12-28 23:37:31 +01:00
parent 5b6bc8a12b
commit 524d446757
11 changed files with 37 additions and 36 deletions

View file

@ -413,7 +413,7 @@ void ScriptApiBase::setOriginFromTableRaw(int index, const char *fxn)
void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
{
SCRIPTAPI_PRECHECKHEADER
//infostream<<"scriptapi_add_object_reference: id="<<cobj->getId()<<std::endl;
assert(getType() == ScriptingType::Server);
// Create object on stack
ObjectRef::create(L, cobj); // Puts ObjectRef (as userdata) on stack
@ -434,7 +434,7 @@ void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
void ScriptApiBase::removeObjectReference(ServerActiveObject *cobj)
{
SCRIPTAPI_PRECHECKHEADER
//infostream<<"scriptapi_rm_object_reference: id="<<cobj->getId()<<std::endl;
assert(getType() == ScriptingType::Server);
// Get core.object_refs table
lua_getglobal(L, "core");
@ -459,6 +459,7 @@ void ScriptApiBase::removeObjectReference(ServerActiveObject *cobj)
void ScriptApiBase::objectrefGetOrCreate(lua_State *L,
ServerActiveObject *cobj)
{
assert(getType() == ScriptingType::Server);
if (cobj == NULL || cobj->getId() == 0) {
ObjectRef::create(L, cobj);
} else {
@ -472,6 +473,7 @@ void ScriptApiBase::objectrefGetOrCreate(lua_State *L,
void ScriptApiBase::pushPlayerHPChangeReason(lua_State *L, const PlayerHPChangeReason &reason)
{
assert(getType() == ScriptingType::Server);
if (reason.hasLuaReference())
lua_rawgeti(L, LUA_REGISTRYINDEX, reason.lua_reference);
else
@ -503,8 +505,13 @@ void ScriptApiBase::pushPlayerHPChangeReason(lua_State *L, const PlayerHPChangeR
Server* ScriptApiBase::getServer()
{
// Since the gamedef is the server it's still possible to retrieve it in
// e.g. the async environment, but this isn't meant to happen.
// TODO: still needs work
//assert(getType() == ScriptingType::Server);
return dynamic_cast<Server *>(m_gamedef);
}
#ifndef SERVER
Client* ScriptApiBase::getClient()
{