summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_base.cpp7
-rw-r--r--src/script/cpp_api/s_security.cpp1
-rw-r--r--src/script/lua_api/l_camera.cpp21
-rw-r--r--src/script/lua_api/l_localplayer.cpp22
-rw-r--r--src/script/scripting_client.cpp3
5 files changed, 35 insertions, 19 deletions
diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp
index e73f613ce..caa335d76 100644
--- a/src/script/cpp_api/s_base.cpp
+++ b/src/script/cpp_api/s_base.cpp
@@ -232,6 +232,13 @@ void ScriptApiBase::loadModFromMemory(const std::string &mod_name)
void ScriptApiBase::runCallbacksRaw(int nargs,
RunCallbacksMode mode, const char *fxn)
{
+#ifndef SERVER
+ // Hard fail for bad guarded callbacks
+ // Only run callbacks when the scripting enviroment is loaded
+ FATAL_ERROR_IF(m_type == ScriptingType::Client &&
+ !getClient()->modsLoaded(), fxn);
+#endif
+
#ifdef SCRIPTAPI_LOCK_DEBUG
assert(m_lock_recursion_count > 0);
#endif
diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp
index 876c7761a..d972be980 100644
--- a/src/script/cpp_api/s_security.cpp
+++ b/src/script/cpp_api/s_security.cpp
@@ -264,6 +264,7 @@ void ScriptApiSecurity::initializeSecurityClient()
};
static const char *debug_whitelist[] = {
"getinfo",
+ "traceback"
};
#if USE_LUAJIT
diff --git a/src/script/lua_api/l_camera.cpp b/src/script/lua_api/l_camera.cpp
index 462006777..80071b3b8 100644
--- a/src/script/lua_api/l_camera.cpp
+++ b/src/script/lua_api/l_camera.cpp
@@ -31,19 +31,24 @@ LuaCamera::LuaCamera(Camera *m) : m_camera(m)
void LuaCamera::create(lua_State *L, Camera *m)
{
+ lua_getglobal(L, "core");
+ luaL_checktype(L, -1, LUA_TTABLE);
+ int objectstable = lua_gettop(L);
+ lua_getfield(L, -1, "camera");
+
+ // Duplication check
+ if (lua_type(L, -1) == LUA_TUSERDATA) {
+ lua_pop(L, 1);
+ return;
+ }
+
LuaCamera *o = new LuaCamera(m);
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
luaL_getmetatable(L, className);
lua_setmetatable(L, -2);
- int camera_object = lua_gettop(L);
-
- lua_getglobal(L, "core");
- luaL_checktype(L, -1, LUA_TTABLE);
- int coretable = lua_gettop(L);
-
- lua_pushvalue(L, camera_object);
- lua_setfield(L, coretable, "camera");
+ lua_pushvalue(L, lua_gettop(L));
+ lua_setfield(L, objectstable, "camera");
}
int LuaCamera::l_set_camera_mode(lua_State *L)
diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp
index 7444d0e88..3e14e48e4 100644
--- a/src/script/lua_api/l_localplayer.cpp
+++ b/src/script/lua_api/l_localplayer.cpp
@@ -30,20 +30,24 @@ LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m) : m_localplayer(m)
void LuaLocalPlayer::create(lua_State *L, LocalPlayer *m)
{
+ lua_getglobal(L, "core");
+ luaL_checktype(L, -1, LUA_TTABLE);
+ int objectstable = lua_gettop(L);
+ lua_getfield(L, -1, "localplayer");
+
+ // Duplication check
+ if (lua_type(L, -1) == LUA_TUSERDATA) {
+ lua_pop(L, 1);
+ return;
+ }
+
LuaLocalPlayer *o = new LuaLocalPlayer(m);
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
luaL_getmetatable(L, className);
lua_setmetatable(L, -2);
- // Keep localplayer object stack id
- int localplayer_object = lua_gettop(L);
-
- lua_getglobal(L, "core");
- luaL_checktype(L, -1, LUA_TTABLE);
- int coretable = lua_gettop(L);
-
- lua_pushvalue(L, localplayer_object);
- lua_setfield(L, coretable, "localplayer");
+ lua_pushvalue(L, lua_gettop(L));
+ lua_setfield(L, objectstable, "localplayer");
}
int LuaLocalPlayer::l_get_velocity(lua_State *L)
diff --git a/src/script/scripting_client.cpp b/src/script/scripting_client.cpp
index 86e5f2874..239c98e57 100644
--- a/src/script/scripting_client.cpp
+++ b/src/script/scripting_client.cpp
@@ -84,8 +84,7 @@ void ClientScripting::InitializeModApi(lua_State *L, int top)
void ClientScripting::on_client_ready(LocalPlayer *localplayer)
{
- lua_State *L = getStack();
- LuaLocalPlayer::create(L, localplayer);
+ LuaLocalPlayer::create(getStack(), localplayer);
}
void ClientScripting::on_camera_ready(Camera *camera)