mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add lua_absindex (and also lua_ispseudo)
This commit is contained in:
parent
07a0e0e111
commit
bf95440812
2 changed files with 8 additions and 0 deletions
|
@ -21,6 +21,7 @@
|
|||
#define LUA_ENVIRONINDEX (-10001)
|
||||
#define LUA_GLOBALSINDEX (-10002)
|
||||
#define lua_upvalueindex(i) (LUA_GLOBALSINDEX - (i))
|
||||
#define lua_ispseudo(i) ((i) <= LUA_REGISTRYINDEX)
|
||||
|
||||
/* thread status; 0 is OK */
|
||||
enum lua_Status
|
||||
|
@ -108,6 +109,7 @@ LUA_API int lua_isthreadreset(lua_State* L);
|
|||
/*
|
||||
** basic stack manipulation
|
||||
*/
|
||||
LUA_API int lua_absindex(lua_State* L, int idx);
|
||||
LUA_API int lua_gettop(lua_State* L);
|
||||
LUA_API void lua_settop(lua_State* L, int idx);
|
||||
LUA_API void lua_pushvalue(lua_State* L, int idx);
|
||||
|
|
|
@ -170,6 +170,12 @@ lua_State* lua_mainthread(lua_State* L)
|
|||
** basic stack manipulation
|
||||
*/
|
||||
|
||||
int lua_absindex(lua_State* L, int idx)
|
||||
{
|
||||
api_check(L, (idx > 0 && idx <= L->top - L->base) || (idx < 0 && -idx <= L->top - L->base) || lua_ispseudo(idx));
|
||||
return idx > 0 || lua_ispseudo(idx) ? idx : cast_int(L->top - L->base) + idx + 1;
|
||||
}
|
||||
|
||||
int lua_gettop(lua_State* L)
|
||||
{
|
||||
return cast_int(L->top - L->base);
|
||||
|
|
Loading…
Add table
Reference in a new issue