laruence / php-lua

This extension embeds the lua interpreter and offers an OO-API to lua variables and functions.
http://pecl.php.net/package/lua
Other
149 stars 50 forks source link

assert() and error() in Lua module loaded by custom package loader raise exception in closure #23

Open ghost opened 8 years ago

ghost commented 8 years ago

I am trying to use php-lua with a custom package loader loading lua scripts and modules from a remote server. I ran into an issue with assert and error inside my modules. When an assert throws or when I call the Lua error function, php-lua raises an exception:

call to lua function (null) failed
#0 [internal function]: LuaClosure->__invoke()
#1 [internal function]: LuaClosure->__invoke()
#2 /path/to/bug-assert.php(34): Lua->eval('local m = requi...')
#3 {main}

I attached a test case showing this problem. The test case installs a custom package loader load_package which tells Lua to call the PHP run_script function (which in my real application fetches code from a remote server) when a module is required. run_script loads a module which exposes a single function func containing asserts. When the main script calls func any assert that doesn't pass will throw a LuaClosure exception. Same for when the function calls error. If I move the assert to the module's main context, it works as expected.

I tested the 1.1.0 release from PECL and the master branch on GitHub.

bug-assert.phpt