对LuaException进行定义:lua代码和error方法抛出的异常才是LuaException#52
Open
flysion wants to merge 3 commits intolaruence:masterfrom
Open
对LuaException进行定义:lua代码和error方法抛出的异常才是LuaException#52flysion wants to merge 3 commits intolaruence:masterfrom
flysion wants to merge 3 commits intolaruence:masterfrom
Conversation
当前的lua扩展有一个很大的问题:把一个PHP方法registerCallback给lua之后,如果lua调用这个方法出现php的异常,lua的代码还是会继续往下走,示例:
```
$lua->registerCallback("test", function() {
throw new \Exception("test");
});
$lua->eval(<<<LUA
test() -- php 抛出了异常
print("Hello php.") -- 代码继续走到了这里
LUA
);
```
---
以上是题外话,但是和这个改进相关。当lua侧代码出现了问题需要终止的时候,只有一种终止方法,那就是error方法。php侧需要捕获这个异常做一些特殊处理的时候只需要判断 `$e instanceof \LuaException`。其次 php 需要得到 error 方法的参数,示例:
```
try {
$lua->eval("error({code=1,message='test'})");
} catch(\LuaException $e) {
var_dump($e->err);
}
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
当前的lua扩展有一个很大的问题:把一个PHP方法registerCallback给lua之后,如果lua调用这个方法出现php的异常,lua的代码还是会继续往下走,示例:
以上是题外话,但是和这个改进相关。当lua侧代码出现了问题需要终止的时候,只有一种终止方法,那就是error方法。php侧需要捕获这个异常做一些特殊处理的时候只需要判断
$e instanceof \LuaException。其次 php 需要得到 error 方法的参数,示例: