#include "common/c_converter.h"
#include "serverobject.h"
#include "filesys.h"
-#include "mods.h"
+#include "content/mods.h"
#include "porting.h"
#include "util/string.h"
#include "server.h"
#ifndef SERVER
-#include "client.h"
+#include "client/client.h"
#endif
#include <cstdio>
#include <cstdarg>
#include "script/common/c_content.h"
+#include "content_sao.h"
#include <sstream>
{
std::ostringstream oss;
oss << "LUA PANIC: unprotected error in call to Lua API ("
- << lua_tostring(L, -1) << ")";
+ << readParam<std::string>(L, -1) << ")";
FATAL_ERROR(oss.str().c_str());
// NOTREACHED
return 0;
{ LUA_JITLIBNAME, luaopen_jit },
#endif
};
-
+
for (const std::pair<std::string, lua_CFunction> &lib : m_libs) {
lua_pushcfunction(L, lib.second);
lua_pushstring(L, lib.first.c_str());
}
ok = ok && !lua_pcall(L, 0, 0, error_handler);
if (!ok) {
- std::string error_msg = lua_tostring(L, -1);
+ std::string error_msg = readParam<std::string>(L, -1);
lua_pop(L, 2); // Pop error message and error handler
throw ModError("Failed to load and run script from " +
script_path + ":\n" + error_msg);
int t = lua_type(m_luastack, i);
switch (t) {
case LUA_TSTRING: /* strings */
- o << "\"" << lua_tostring(m_luastack, i) << "\"";
+ o << "\"" << readParam<std::string>(m_luastack, i) << "\"";
break;
case LUA_TBOOLEAN: /* booleans */
- o << (lua_toboolean(m_luastack, i) ? "true" : "false");
+ o << (readParam<bool>(m_luastack, i) ? "true" : "false");
break;
case LUA_TNUMBER: /* numbers */ {
char buf[10];
- snprintf(buf, 10, "%lf", lua_tonumber(m_luastack, i));
+ porting::mt_snprintf(buf, sizeof(buf), "%lf", lua_tonumber(m_luastack, i));
o << buf;
break;
}
}
}
+void ScriptApiBase::pushPlayerHPChangeReason(lua_State *L, const PlayerHPChangeReason &reason)
+{
+ if (reason.hasLuaReference())
+ lua_rawgeti(L, LUA_REGISTRYINDEX, reason.lua_reference);
+ else
+ lua_newtable(L);
+
+ lua_getfield(L, -1, "type");
+ bool has_type = (bool)lua_isstring(L, -1);
+ lua_pop(L, 1);
+ if (!has_type) {
+ lua_pushstring(L, reason.getTypeAsString().c_str());
+ lua_setfield(L, -2, "type");
+ }
+
+ lua_pushstring(L, reason.from_mod ? "mod" : "engine");
+ lua_setfield(L, -2, "from");
+
+ if (reason.object) {
+ objectrefGetOrCreate(L, reason.object);
+ lua_setfield(L, -2, "object");
+ }
+ if (!reason.node.empty()) {
+ lua_pushstring(L, reason.node.c_str());
+ lua_setfield(L, -2, "node");
+ }
+}
+
Server* ScriptApiBase::getServer()
{
return dynamic_cast<Server *>(m_gamedef);