Added the scripts directory to lua's path
This will allow modules.
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
local mapMaker = {}
|
||||||
|
|
||||||
|
function mapMaker.foo()
|
||||||
|
print("--> Hello map maker! <--")
|
||||||
|
end
|
||||||
|
|
||||||
|
return mapMaker
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
print("Lua script check")
|
print("Lua script check")
|
||||||
|
|
||||||
|
mapMaker = require "map_maker"
|
||||||
|
mapMaker.foo()
|
||||||
|
|
||||||
--uber lazy declarations
|
--uber lazy declarations
|
||||||
function math.sqr(x) return x*x end
|
function math.sqr(x) return x*x end
|
||||||
function math.dist(x, y, i, j) return math.sqrt(math.sqr(x - i) + math.sqr(y - j)) end
|
function math.dist(x, y, i, j) return math.sqrt(math.sqr(x - i) + math.sqr(y - j)) end
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -71,8 +72,27 @@ void ServerApplication::Init(int argc, char* argv[]) {
|
|||||||
throw(std::runtime_error("Failed to initialize lua"));
|
throw(std::runtime_error("Failed to initialize lua"));
|
||||||
}
|
}
|
||||||
luaL_openlibs(luaState);
|
luaL_openlibs(luaState);
|
||||||
|
|
||||||
std::cout << "Initialized lua" << std::endl;
|
std::cout << "Initialized lua" << std::endl;
|
||||||
|
|
||||||
|
//append config["dir.scripts"] to the module path
|
||||||
|
if (config["dir.scripts"].size() > 0) {
|
||||||
|
//get the original path
|
||||||
|
lua_getglobal(luaState, "package");
|
||||||
|
lua_getfield(luaState, -1, "path");
|
||||||
|
|
||||||
|
//build & push the message
|
||||||
|
std::ostringstream path;
|
||||||
|
path << lua_tostring(luaState, -1) << ";" << config["dir.scripts"] << "?.lua";
|
||||||
|
lua_pushstring(luaState, path.str().c_str());
|
||||||
|
|
||||||
|
//set the new path and clean up the stack
|
||||||
|
lua_setfield(luaState, -3, "path");
|
||||||
|
lua_pop(luaState, 2);
|
||||||
|
|
||||||
|
std::cout << "\tLua script directory appended" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Setup the objects
|
//Setup the objects
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user