简体   繁体   中英

Lua in iOS Objective C - path for Require

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?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM