lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


There are two problems:

- your C code should use lua_pcall to call whatever it calls, so you can catch the error. The lua library now panics because it can't deliver the error. Typically you write a C function that executes the Lua file, and call it using lua_pcall from the C main function. Look at the lua interpreter lua.c file for an example.

- when the binary is run from Xcode the process' current directory is not the directory you put the call_a.lua and call_b.lua files in, so the Lua runtime can't find them. The current directory is not necessarily the directory the executable is stored in, especially when you build a macOS application. You should probably modify the Lua 'package.path' variable in your C code to include the directory your Lua files are stored in before the first lua_call or lua_pcall. That way you can move the application around without breaking things.




On Wed, Oct 30, 2019 at 12:11 AM Judith" <luobinjuan@qq.com> wrote:
Hi! I'm Judith!
I encounter a problem while OC calls lua file by C- API,
call_a.lua  call_b.lua are in the same director,
oc pcall call_a.lua
call_a.lua require("call_b")
but oc always reports error as follow:

/Users/judith/Library/Developer/Xcode/DerivedData/CallLuaTest-axkrsjebjsgswnfllylhmergmvmv/Build/Products/Debug/CallLuaTest.app/Contents/MacOS/CallLuaTest PANIC: unprotected error in call to Lua API (cannot run the lua file: [string "package.path = package.path ..";../Resources/..."]:2: module 'call_b' not found:

no field package.preload['call_b']

no file '/usr/local/share/lua/5.3/call_b.lua'

no file '/usr/local/share/lua/5.3/call_b/init.lua'

no file '/usr/local/lib/lua/5.3/call_b.lua'

no file '/usr/local/lib/lua/5.3/call_b/init.lua'

no file './call_b.lua'

no file './call_b/init.lua'

no file '../Resources/call_b.lua'

no file '/usr/local/lib/lua/5.3/call_b.so'

no file '/usr/local/lib/lua/5.3/loadall.so'

no file './call_b.so')

there is no problem in C project which be built by Xcode with the two lua files
I have been struggling with this problem for two days.
I would be appreciate it if there is a solution.

Thanks!


--