From fb028a899feb059e47a2c763fcb1a6222766d012 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sun, 15 Feb 2015 19:32:19 +0100 Subject: [PATCH] Moved setting of package.path in lua to init.lua --- data/levels/scripts/Template.lua | 2 -- data/levels/scripts/global.lua | 4 ++-- data/levels/scripts/init.lua | 4 ++++ data/levels/scripts/openFirstDoor.lua | 2 -- data/levels/scripts/openFirstDoorUndo.lua | 2 -- loader.cc | 4 ++++ 6 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 data/levels/scripts/init.lua diff --git a/data/levels/scripts/Template.lua b/data/levels/scripts/Template.lua index df848f8..97aef83 100644 --- a/data/levels/scripts/Template.lua +++ b/data/levels/scripts/Template.lua @@ -1,5 +1,3 @@ ---I have no idea why this hack from the internet works, but it does... -package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path local global = require( "global" ) if(global.triggeredSCRIPTNAME == nil) then global.triggeredSCRIPTNAME = false diff --git a/data/levels/scripts/global.lua b/data/levels/scripts/global.lua index c68517d..4be613b 100644 --- a/data/levels/scripts/global.lua +++ b/data/levels/scripts/global.lua @@ -1,3 +1,3 @@ --global variable space -local M = {} -return M +local global = {} +return global diff --git a/data/levels/scripts/init.lua b/data/levels/scripts/init.lua new file mode 100644 index 0000000..222c9f2 --- /dev/null +++ b/data/levels/scripts/init.lua @@ -0,0 +1,4 @@ +-- Inits search path for require. +-- This file needs to stay next to the other scripts. + +package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path diff --git a/data/levels/scripts/openFirstDoor.lua b/data/levels/scripts/openFirstDoor.lua index b36148e..dba1c32 100644 --- a/data/levels/scripts/openFirstDoor.lua +++ b/data/levels/scripts/openFirstDoor.lua @@ -1,5 +1,3 @@ ---I have no idea why this hack from the internet works, but it does... -package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path local global = require( "global" ) if(global.triggeredOpenFirstDoor == nil) then global.triggeredOpenFirstDoor = false diff --git a/data/levels/scripts/openFirstDoorUndo.lua b/data/levels/scripts/openFirstDoorUndo.lua index 6fd9de2..facc789 100644 --- a/data/levels/scripts/openFirstDoorUndo.lua +++ b/data/levels/scripts/openFirstDoorUndo.lua @@ -1,5 +1,3 @@ ---I have no idea why this hack from the internet works, but it does... -package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path local global = require( "global" ) if(global.triggeredOpenFirstDoorUndo == nil) then global.triggeredOpenFirstDoorUndo = true diff --git a/loader.cc b/loader.cc index ca515ab..4f3cee2 100644 --- a/loader.cc +++ b/loader.cc @@ -380,6 +380,10 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa }//iterating over all compositions in Level.xml //load triggers + + // call init.lua to init the module load path in Lua + std::string initLuaPath = scriptPath + "init.lua"; + luaL_dofile(level->getLuaState(), initLuaPath.c_str()); XMLElement* composition = doc->FirstChildElement("composition"); for(; composition; composition=composition->NextSiblingElement("composition")){ XMLElement* xmlTrigger = composition->FirstChildElement("trigger");