aboutsummaryrefslogtreecommitdiff
path: root/src/compat.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/compat.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/compat.cpp b/src/compat.cpp
index 4076aa6..1f8eaf9 100644
--- a/src/compat.cpp
+++ b/src/compat.cpp
@@ -5,10 +5,10 @@
5 5
6// ################################################################################################# 6// #################################################################################################
7 7
8int luaG_getalluservalues(lua_State* const L_, int const idx_) 8int luaG_getalluservalues(lua_State* const L_, StackIndex const idx_)
9{ 9{
10 STACK_CHECK_START_REL(L_, 0); 10 STACK_CHECK_START_REL(L_, 0);
11 int const _idx{ luaG_absindex(L_, idx_) }; 11 StackIndex const _idx{ luaG_absindex(L_, idx_) };
12 int _nuv{ 0 }; 12 int _nuv{ 0 };
13 do { 13 do {
14 // we don't know how many uservalues we are going to extract, there might be a lot... 14 // we don't know how many uservalues we are going to extract, there might be a lot...
@@ -27,12 +27,12 @@ int luaG_getalluservalues(lua_State* const L_, int const idx_)
27LuaType luaG_getmodule(lua_State* const L_, std::string_view const& name_) 27LuaType luaG_getmodule(lua_State* const L_, std::string_view const& name_)
28{ 28{
29 STACK_CHECK_START_REL(L_, 0); 29 STACK_CHECK_START_REL(L_, 0);
30 LuaType _type{ luaG_getfield(L_, LUA_REGISTRYINDEX, LUA_LOADED_TABLE) }; // L_: _R._LOADED|nil 30 LuaType _type{ luaG_getfield(L_, kIdxRegistry, LUA_LOADED_TABLE) }; // L_: _R._LOADED|nil
31 if (_type != LuaType::TABLE) { // L_: _R._LOADED|nil 31 if (_type != LuaType::TABLE) { // L_: _R._LOADED|nil
32 STACK_CHECK(L_, 1); 32 STACK_CHECK(L_, 1);
33 return _type; 33 return _type;
34 } 34 }
35 _type = luaG_getfield(L_, -1, name_); // L_: _R._LOADED {module}|nil 35 _type = luaG_getfield(L_, kIdxTop, name_); // L_: _R._LOADED {module}|nil
36 lua_remove(L_, -2); // L_: {module}|nil 36 lua_remove(L_, -2); // L_: {module}|nil
37 STACK_CHECK(L_, 1); 37 STACK_CHECK(L_, 1);
38 return _type; 38 return _type;
@@ -45,17 +45,17 @@ LuaType luaG_getmodule(lua_State* const L_, std::string_view const& name_)
45// ################################################################################################# 45// #################################################################################################
46 46
47// Copied from Lua 5.2 loadlib.c 47// Copied from Lua 5.2 loadlib.c
48int luaL_getsubtable(lua_State* L_, int idx_, const char* fname_) 48int luaL_getsubtable(lua_State* const L_, StackIndex const idx_, char const* fname_)
49{ 49{
50 lua_getfield(L_, idx_, fname_); 50 lua_getfield(L_, idx_, fname_);
51 if (lua_istable(L_, -1)) 51 if (lua_istable(L_, -1))
52 return 1; /* table already there */ 52 return 1; /* table already there */
53 else { 53 else {
54 lua_pop(L_, 1); /* remove previous result */ 54 lua_pop(L_, 1); /* remove previous result */
55 idx_ = luaG_absindex(L_, idx_); 55 StackIndex const _absidx{ luaG_absindex(L_, idx_) };
56 lua_newtable(L_); 56 lua_newtable(L_);
57 lua_pushvalue(L_, -1); /* copy to be left at top */ 57 lua_pushvalue(L_, -1); /* copy to be left at top */
58 lua_setfield(L_, idx_, fname_); /* assign new table to field */ 58 lua_setfield(L_, _absidx, fname_); /* assign new table to field */
59 return 0; /* false, because did not find table there */ 59 return 0; /* false, because did not find table there */
60 } 60 }
61} 61}
@@ -66,7 +66,7 @@ void luaL_requiref(lua_State* L_, const char* modname_, lua_CFunction openf_, in
66 lua_pushcfunction(L_, openf_); 66 lua_pushcfunction(L_, openf_);
67 lua_pushstring(L_, modname_); /* argument to open function */ 67 lua_pushstring(L_, modname_); /* argument to open function */
68 lua_call(L_, 1, 1); /* open module */ 68 lua_call(L_, 1, 1); /* open module */
69 luaL_getsubtable(L_, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); 69 luaL_getsubtable(L_, kIdxRegistry, LUA_LOADED_TABLE);
70 lua_pushvalue(L_, -2); /* make copy of module (call result) */ 70 lua_pushvalue(L_, -2); /* make copy of module (call result) */
71 lua_setfield(L_, -2, modname_); /* _LOADED[modname] = module */ 71 lua_setfield(L_, -2, modname_); /* _LOADED[modname] = module */
72 lua_pop(L_, 1); /* remove _LOADED table */ 72 lua_pop(L_, 1); /* remove _LOADED table */
@@ -92,7 +92,7 @@ void* lua_newuserdatauv(lua_State* L_, size_t sz_, [[maybe_unused]] int nuvalue_
92// ################################################################################################# 92// #################################################################################################
93 93
94// push on stack uservalue #n of full userdata at idx 94// push on stack uservalue #n of full userdata at idx
95int lua_getiuservalue(lua_State* const L_, int const idx_, int const n_) 95int lua_getiuservalue(lua_State* const L_, StackIndex const idx_, int const n_)
96{ 96{
97 STACK_CHECK_START_REL(L_, 0); 97 STACK_CHECK_START_REL(L_, 0);
98 // full userdata can have only 1 uservalue before 5.4 98 // full userdata can have only 1 uservalue before 5.4
@@ -129,7 +129,7 @@ int lua_getiuservalue(lua_State* const L_, int const idx_, int const n_)
129 129
130// Pops a value from the stack and sets it as the new n-th user value associated to the full userdata at the given index. 130// Pops a value from the stack and sets it as the new n-th user value associated to the full userdata at the given index.
131// Returns 0 if the userdata does not have that value. 131// Returns 0 if the userdata does not have that value.
132int lua_setiuservalue(lua_State* L_, int idx_, int n_) 132int lua_setiuservalue(lua_State* const L_, StackIndex const idx_, int const n_)
133{ 133{
134 if (n_ > 1 134 if (n_ > 1
135#if LUA_VERSION_NUM == 501 135#if LUA_VERSION_NUM == 501