Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lua_rawget / lua_rawset is not catched by lua_pcall #810

Closed
hyee opened this issue Feb 17, 2022 · 2 comments
Closed

lua_rawget / lua_rawset is not catched by lua_pcall #810

hyee opened this issue Feb 17, 2022 · 2 comments
Labels

Comments

@hyee
Copy link

hyee commented Feb 17, 2022

With below function

static void test(lua_State *L) {
    lua_pushnil(L); //simulate an exception where a table is expected here
    lua_pushstring(L,"abcd");
    lua_rawget(L,-2);
}

If call this function with lua_pcall, the program directly crashes. And if change lua_rawget as lua_gettable, the program correctly catches the error attempt to index a nil value. The same issue happens on lua_rawset.

My OS is Win10 and LuaJIT is up to date, is this behaviour expected? Thanks.

@hyee hyee changed the title lua_rawset / lua_rawset is not catched by lua_pcall lua_rawget / lua_rawset is not catched by lua_pcall Feb 17, 2022
@MikePall
Copy link
Member

First, the behavior is the same with Lua, so the question does not belong here.

The Lua/C API is a low-level API. It assumes certain arguments on the stack to be of the correct type. You can enable API checks in the Makefile to catch (some) of this API misuse in your programs.

@hyee
Copy link
Author

hyee commented Feb 17, 2022

Noted with thanks, I didn't realize -DLUA_USE_APICHECK can be used for debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants