From 3e95b8a1587ebce9443d4d716645798bfbb630f2 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 4 Dec 2011 03:45:02 +0200 Subject: Determine light_propagates from paramtype --- src/script.cpp | 9 ++++++++- src/script.h | 1 + src/scriptapi.cpp | 16 +++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/script.cpp b/src/script.cpp index 8b1b7013e..14c23e009 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -35,13 +35,19 @@ LuaError::LuaError(lua_State *L, const std::string &s) { m_s = "LuaError: "; m_s += s + "\n"; + m_s += script_get_backtrace(L); +} + +std::string script_get_backtrace(lua_State *L) +{ + std::string s; lua_getfield(L, LUA_GLOBALSINDEX, "debug"); if(lua_istable(L, -1)){ lua_getfield(L, -1, "traceback"); if(lua_isfunction(L, -1)){ lua_call(L, 0, 1); if(lua_isstring(L, -1)){ - m_s += lua_tostring(L, -1); + s += lua_tostring(L, -1); } lua_pop(L, 1); } @@ -50,6 +56,7 @@ LuaError::LuaError(lua_State *L, const std::string &s) } } lua_pop(L, 1); + return s; } void script_error(lua_State *L, const char *fmt, ...) diff --git a/src/script.h b/src/script.h index 3c056ae35..3bf5342f5 100644 --- a/src/script.h +++ b/src/script.h @@ -41,6 +41,7 @@ public: lua_State* script_init(); void script_deinit(lua_State *L); +std::string script_get_backtrace(lua_State *L); void script_error(lua_State *L, const char *fmt, ...); bool script_load(lua_State *L, const char *path); diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index d7382b98b..ffbce9167 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -455,6 +455,18 @@ static void setfloatfield(lua_State *L, int table, lua_setfield(L, table, fieldname); } +static void warn_if_field_exists(lua_State *L, int table, + const char *fieldname, const std::string &message) +{ + lua_getfield(L, table, fieldname); + if(!lua_isnil(L, -1)){ + infostream<