Skip to content

Commit 07153cd

Browse files
committed
Added GetUpvalueIndex to ILuaBase class
Moved lua_* function definitions to GarrysMod::Lua namespace
1 parent a180291 commit 07153cd

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

include/GarrysMod/Lua/LuaBase.h

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,40 @@
1111

1212
struct lua_State;
1313

14-
extern "C"
15-
{
16-
void lua_getfenv( lua_State *L, int idx );
17-
int lua_setfenv( lua_State *L, int idx );
18-
const char *lua_pushvfstring( lua_State *L, const char *fmt, va_list argp );
19-
int lua_error( lua_State *L );
20-
int luaL_typerror( lua_State *L, int narg, const char *tname );
21-
const void *lua_topointer( lua_State *L, int idx );
22-
int luaL_callmeta( lua_State *L, int idx, const char *e );
23-
}
24-
2514
namespace GarrysMod
2615
{
2716
namespace Lua
2817
{
18+
extern "C"
19+
{
20+
void lua_getfenv( lua_State *L, int idx );
21+
int lua_setfenv( lua_State *L, int idx );
22+
const char *lua_pushvfstring( lua_State *L, const char *fmt, va_list argp );
23+
int lua_error( lua_State *L );
24+
int luaL_typerror( lua_State *L, int narg, const char *tname );
25+
const void *lua_topointer( lua_State *L, int idx );
26+
int luaL_callmeta( lua_State *L, int idx, const char *e );
27+
}
28+
2929
typedef int ( *CFunc )( lua_State* L );
3030

31+
// For use with ILuaBase::PushSpecial
32+
enum
33+
{
34+
SPECIAL_GLOB, // Global table
35+
SPECIAL_ENV, // Environment table
36+
SPECIAL_REG, // Registry table
37+
};
38+
39+
// Use these when calling ILuaBase::GetField or ILuaBase::SetField for example,
40+
// instead of pushing the specified table
41+
enum
42+
{
43+
INDEX_GLOBAL = -10002, // Global table
44+
INDEX_ENVIRONMENT, // Environment table
45+
INDEX_REGISTRY, // Registry table
46+
};
47+
3148
//
3249
// Use this to communicate between C and Lua
3350
//
@@ -407,26 +424,15 @@ namespace GarrysMod
407424
return luaL_callmeta( state, iStackPos, e );
408425
}
409426

427+
// Produces the pseudo-index of an upvalue at iPos
428+
static inline int GetUpvalueIndex( int iPos )
429+
{
430+
return static_cast<int>( INDEX_GLOBAL ) - iPos;
431+
}
432+
410433
private:
411434
lua_State *state;
412435
};
413-
414-
// For use with ILuaBase::PushSpecial
415-
enum
416-
{
417-
SPECIAL_GLOB, // Global table
418-
SPECIAL_ENV, // Environment table
419-
SPECIAL_REG, // Registry table
420-
};
421-
422-
// Use these when calling ILuaBase::GetField or ILuaBase::SetField for example,
423-
// instead of pushing the specified table
424-
enum
425-
{
426-
INDEX_GLOBAL = -10002, // Global table
427-
INDEX_ENVIRONMENT, // Environment table
428-
INDEX_REGISTRY, // Registry table
429-
};
430436
}
431437
}
432438

0 commit comments

Comments
 (0)