开发者

Differing paths for lua script and app

开发者 https://www.devze.com 2022-12-23 12:29 出处:网络
My problem is that I\'m having trouble specifying paths for Lua to look in. For example, in my script I have a require(\"someScript\") line that works perfectly (it is able to use functions from some

My problem is that I'm having trouble specifying paths for Lua to look in.

For example, in my script I have a require("someScript") line that works perfectly (it is able to use functions from someScript when the script is run standalone.

However, when I run my app, the script fails. I believe this is because Lua is looking in a location relative to the application rather than relative to the script.

Hardcoding the entire path down to the drive isn't an option since people can download the game wherever they like so the highest I can go is the root folder for the game.

We have XML files to load in information on objects. In them, when we specify the script the object uses, we only have to do some开发者_C百科thing like Content/Core/Scripts/someScript.lua where Content is in the same directory as Debug and the app is located inside Debug. If I try putting that (the Content/Core...) in Lua's package.path I get errors when I try to run the script standalone.

I'm really stuck, and am not sure how to solve this. Any help is appreciated. Thanks.

P.S. When I print out the default package.path in the app I see syntax like ;.\?.lua in a sequence like...

;.\?.lua;c:...(long file path)\Debug\?.lua; I assume the ; means the end of the path, but I have no idea what the .\?.lua means. Any Lua file in the directory?


You can customize the way require loads modules by putting your own loader into the package.loaders table. See here:

http://www.lua.org/manual/5.1/manual.html#pdf-package.loaders

If you want to be sure that things are nicely sandboxed, you'll probably want to remove all the default loaders and replace them with one that does exactly what you want and nothing more. (It will probably be somewhat similar to one of the existing ones, so you can use those as a guide.)

0

精彩评论

暂无评论...
验证码 换一张
取 消