]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/script/cpp_api/s_base.cpp
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / script / cpp_api / s_base.cpp
index 595c9e540b3eec64f566adcf9d95d89a5068135d..ae4a1677156b88b6d1021a23cdde300f1b70da3f 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "cpp_api/s_internal.h"
 #include "cpp_api/s_security.h"
 #include "lua_api/l_object.h"
+#include "lua_api/l_clientobject.h"
 #include "common/c_converter.h"
 #include "server/player_sao.h"
 #include "filesys.h"
@@ -85,9 +86,9 @@ ScriptApiBase::ScriptApiBase(ScriptingType type):
 
        lua_atpanic(m_luastack, &luaPanic);
 
-       if (m_type == ScriptingType::Client)
+       /*if (m_type == ScriptingType::Client)
                clientOpenLibs(m_luastack);
-       else
+       else*/
                luaL_openlibs(m_luastack);
 
        // Load bit library
@@ -365,13 +366,18 @@ void ScriptApiBase::setOriginFromTableRaw(int index, const char *fxn)
  *     since we lose control over the ref and the contained pointer.
  */
 
-void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
+void ScriptApiBase::addObjectReference(ActiveObject *cobj)
 {
        SCRIPTAPI_PRECHECKHEADER
        //infostream<<"scriptapi_add_object_reference: id="<<cobj->getId()<<std::endl;
 
        // Create object on stack
-       ObjectRef::create(L, cobj); // Puts ObjectRef (as userdata) on stack
+#ifndef SERVER
+       if (m_type == ScriptingType::Client)
+               ClientObjectRef::create(L, dynamic_cast<ClientActiveObject *>(cobj));
+       else
+#endif
+               ObjectRef::create(L, dynamic_cast<ServerActiveObject *>(cobj)); // Puts ObjectRef (as userdata) on stack
        int object = lua_gettop(L);
 
        // Get core.object_refs table
@@ -386,7 +392,7 @@ void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
        lua_settable(L, objectstable);
 }
 
-void ScriptApiBase::removeObjectReference(ServerActiveObject *cobj)
+void ScriptApiBase::removeObjectReference(ActiveObject *cobj)
 {
        SCRIPTAPI_PRECHECKHEADER
        //infostream<<"scriptapi_rm_object_reference: id="<<cobj->getId()<<std::endl;
@@ -401,7 +407,12 @@ void ScriptApiBase::removeObjectReference(ServerActiveObject *cobj)
        lua_pushnumber(L, cobj->getId()); // Push id
        lua_gettable(L, objectstable);
        // Set object reference to NULL
-       ObjectRef::set_null(L);
+#ifndef SERVER
+       if (m_type == ScriptingType::Client)
+               ClientObjectRef::set_null(L);
+       else
+#endif
+               ObjectRef::set_null(L);
        lua_pop(L, 1); // pop object
 
        // Set object_refs[id] = nil
@@ -424,7 +435,6 @@ void ScriptApiBase::objectrefGetOrCreate(lua_State *L,
                                        << ", this is probably a bug." << std::endl;
        }
 }
-
 void ScriptApiBase::pushPlayerHPChangeReason(lua_State *L, const PlayerHPChangeReason &reason)
 {
        if (reason.hasLuaReference())