summaryrefslogtreecommitdiff
path: root/src/scripting/lua.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r--src/scripting/lua.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 86bf38f8..790d6d91 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -26,6 +26,7 @@ extern "C" {
#include <lauxlib.h>
}
+#include "common/resourcemanager.hpp"
#include "game-server/accountconnection.hpp"
#include "game-server/buysell.hpp"
#include "game-server/character.hpp"
@@ -1535,12 +1536,36 @@ static int item_drop(lua_State *s)
}
+static int require_loader(lua_State *s)
+{
+ // Add .lua extension (maybe only do this when it doesn't have it already)
+ std::string filename = luaL_checkstring(s, 1);
+ filename.append(".lua");
+
+ const std::string path = ResourceManager::resolve(filename);
+ if (!path.empty())
+ luaL_loadfile(s, path.c_str());
+ else
+ lua_pushstring(s, "File not found");
+
+ return 1;
+}
+
+
LuaScript::LuaScript():
nbArgs(-1)
{
mState = luaL_newstate();
luaL_openlibs(mState);
+ // Register package loader that goes through the resource manager
+ // table.insert(package.loaders, 2, require_loader)
+ lua_getglobal(mState, "package");
+ lua_getfield(mState, -1, "loaders");
+ lua_pushcfunction(mState, require_loader);
+ lua_rawseti(mState, -2, 2);
+ lua_pop(mState, 2);
+
// Put some callback functions in the scripting environment.
static luaL_reg const callbacks[] = {
{ "npc_create", &npc_create },