-
Notifications
You must be signed in to change notification settings - Fork 381
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
Inconsistency with lua_ref #247
Comments
|
P.S. Since passing LUA_REGISTRYINDEX to lua_ref is likely an error in every case perhaps an |
Ah yes - I was following this page. Perhaps it would be good to list this difference in the documentation somewhere. Unless it's already there and I missed it. |
I encountered a similar problem while working on the Luau port of LuaBridge3 (kunitoki/LuaBridge3#12) and i had to basically write some wrapper calls for luaL_ref and luaL_unref (https://github.com/kunitoki/LuaBridge3/pull/12/files#diff-62eaf77f04843ba30bd2cd74ea720cb4fa899e0d6ab5df08db16280f09e31cb4R18-R72) in order to make it work. in any case i still get issues from unit tests where from time to time when calling void lua_rawgeti(lua_State* L, int idx, int n)
{
luaC_checkthreadsleep(L);
StkId t = index2adr(L, idx);
api_check(L, ttistable(t));
setobj2s(L, L->top, luaH_getnum(hvalue(t), n));
api_incr_top(L); // <<<<<<<<< Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
return;
} |
This indicates that you are exceeding the minimum stack space; if you work with errored or yielded threads, they don't provide a stack space guarantee and as such you need to call lua_checkstack before working with the thread. |
It's strange as LuaJIT automatically grows the stack as needed (to LUA_MAXSTACK). Isn't Luau doing the same ? |
The stack space guarantee that Luau provides is only there when the C function is called from the VM, I'm assuming you're working with threads externally, e.g. the rawgeti call above is not done as part of a C function that is executed from scripts? |
Either way, stack space guarantees are separate from lua_ref - feel free to create a discussion thread for this with more information on the specific situation! It's possible that Luau is stricter on stack space than Lua 5.1 but it's also possible that the code that worked on Lua 5.1 works by accident. This issue will be fixed by adding an assertion to lua_ref later this week to prevent misuse. I'll also create an issue for documentation on the C API which we simply lack atm, which would be a good place to note differences from Lua. |
It seems that |
Yeah that's intentional; |
The correct implementation for luaL_ref in Luau looks something like this I think:
|
- Fix some cases where type checking would overflow the native stack - Improve autocomplete behavior when assigning a partially written function call (not currently exposed through command line tools) - Improve autocomplete type inference feedback for some expressions where previously the type would not be known - Improve quantification performance during type checking for large types - Improve type checking for table literals when the expected type of the table is known because of a type annotation - Fix type checking errors in cases where required module has errors in the resulting type - Fix debug line information for multi-line chained call sequences (Add function name information for "attempt to call a nil value" #255) - lua_newuserdata now takes 2 arguments to match Lua/LuaJIT APIs better; lua_newuserdatatagged should be used if the third argument was non-0. - lua_ref can no longer be used with LUA_REGISTRYINDEX to prevent mistakes when migrating Lua FFI (Inconsistency with lua_ref #247) - Fix assertions and possible crashes when executing script code indirectly via metatable dispatch from lua_equal/lua_lessthan/lua_getfield/etc. (Hitting a crash in an assert after lua_equal is called. #259) - Fix flamegraph scripts to run under Python 2
lua_ref now has an assertion to prevent misuse; subsequent improvements to documentation are tracked in #251 |
Given the following program with regular Lua 5.1:
The output is, as one would expect:
When the following similar program is run on Luau:
The types are suddenly different:
With 5 being
LUA_TSTRING
and 6 beingLUA_TTABLE
.Perhaps I'm missing something in the difference between
lua_ref
andluaL_ref
, but this seems wrong to me on first sight.The text was updated successfully, but these errors were encountered: