Reputation: 230
I'm using lua for scripting in my iOS app. I'm trying to do the simple thing of adding another lua file with 'require'
My Lua files are contained within my project in XCode in the following directory:
Classes/Lua_Code/main.lua
Classes/Lua_Code/luaBase.lua
main.lua is trying to require luaBase.lua as follows -
require('luaBase')
But it never seems to find the file, even though it's in the same folder as main.lua.
I get the following errors in the log
no field package.preload['luaBase'] no file
'./luaBase.lua' no file
'/usr/local/share/lua/5.1/luaBase.lua' no file
'/usr/local/share/lua/5.1/luaBase/init.lua' no file
'/usr/local/lib/lua/5.1/luaBase.lua' no file
'/usr/local/lib/lua/5.1/luaBase/init.lua' no file
'./function/luaBase.lua' no file './luaBase.so' no file
'/usr/local/lib/lua/5.1/luaBase.so' no file
'/usr/local/lib/lua/5.1/loadall.so'
I've tried every other suggestion here, and nothing works..
Can anyone help?
Upvotes: 0
Views: 530
Reputation: 230
I figured it out -
In Objective-C - I do the following: (self runLua: is a method that runs the text in the NSString as a lua command)
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
[self runLua:[NSString stringWithFormat:@"appPath = '%@/?.lua'",bundlePath]];
Then in Lua - I do the following:
package.path = appPath
require('test')
And finally - Lua knows where to find the files!
Upvotes: 1