#include "lua_api/l_object.h"
#include "common/c_converter.h"
#include "serverobject.h"
-#include "debug.h"
#include "filesys.h"
-#include "log.h"
#include "mods.h"
#include "porting.h"
#include "util/string.h"
+#include "server.h"
+#ifndef SERVER
+#include "client.h"
+#endif
extern "C" {
#include <stdio.h>
#include <cstdarg>
+#include <sstream>
class ModNameStorer
*/
ScriptApiBase::ScriptApiBase() :
- m_luastackmutex()
+ m_luastackmutex(),
+ m_gamedef(NULL)
{
#ifdef SCRIPTAPI_LOCK_DEBUG
m_lock_recursion_count = 0;
m_luastack = luaL_newstate();
FATAL_ERROR_IF(!m_luastack, "luaL_newstate() failed");
+ lua_atpanic(m_luastack, &luaPanic);
+
luaL_openlibs(m_luastack);
// Make the ScriptApiBase* accessible to ModApiBase
// Default to false otherwise
m_secure = false;
- m_server = NULL;
m_environment = NULL;
m_guiengine = NULL;
}
lua_close(m_luastack);
}
+int ScriptApiBase::luaPanic(lua_State *L)
+{
+ std::ostringstream oss;
+ oss << "LUA PANIC: unprotected error in call to Lua API ("
+ << lua_tostring(L, -1) << ")";
+ FATAL_ERROR(oss.str().c_str());
+ // NOTREACHED
+ return 0;
+}
+
void ScriptApiBase::loadMod(const std::string &script_path,
const std::string &mod_name)
{
lua_remove(L, -2); // object_refs
lua_remove(L, -2); // core
}
+
+Server* ScriptApiBase::getServer()
+{
+ return dynamic_cast<Server *>(m_gamedef);
+}
+#ifndef SERVER
+Client* ScriptApiBase::getClient()
+{
+ return dynamic_cast<Client *>(m_gamedef);
+}
+#endif