|
| 1 | +// |
| 2 | +// Unlike normal Garry's Mod Common, his will give us the ILuaInterface instead of the ILuaBase. |
| 3 | +// |
| 4 | + |
| 5 | +#ifndef GARRYSMOD_LUA_INTERFACE_H |
| 6 | +#define GARRYSMOD_LUA_INTERFACE_H |
| 7 | + |
| 8 | +#include "sourcesdk/ILuaInterface.h" |
| 9 | + |
| 10 | +struct lua_State |
| 11 | +{ |
| 12 | +#if ( defined( _WIN32 ) || defined( __linux__ ) || defined( __APPLE__ ) ) && \ |
| 13 | + !defined( __x86_64__ ) && !defined( _M_X64 ) |
| 14 | + // Win32, Linux32 and macOS32 |
| 15 | + unsigned char _ignore_this_common_lua_header_[48 + 22]; |
| 16 | +#elif ( defined( _WIN32 ) || defined( __linux__ ) || defined( __APPLE__ ) ) && \ |
| 17 | + ( defined( __x86_64__ ) || defined( _M_X64 ) ) |
| 18 | + // Win64, Linux64 and macOS64 (not tested) |
| 19 | + unsigned char _ignore_this_common_lua_header_[92 + 22]; |
| 20 | +#else |
| 21 | + #error Unsupported platform |
| 22 | +#endif |
| 23 | + |
| 24 | + GarrysMod::Lua::ILuaInterface* luabase; |
| 25 | +}; |
| 26 | + |
| 27 | +#ifndef GMOD |
| 28 | + #ifdef _WIN32 |
| 29 | + #define GMOD_DLL_EXPORT extern "C" __declspec( dllexport ) |
| 30 | + #else |
| 31 | + #define GMOD_DLL_EXPORT extern "C" __attribute__((visibility("default"))) |
| 32 | + #endif |
| 33 | + |
| 34 | + #ifdef GMOD_ALLOW_DEPRECATED |
| 35 | + // Stop using this and use LUA_FUNCTION! |
| 36 | + #define LUA ( state->luabase ) |
| 37 | + |
| 38 | + #define GMOD_MODULE_OPEN() GMOD_DLL_EXPORT int gmod13_open( [[maybe_unused]] lua_State* state ) |
| 39 | + #define GMOD_MODULE_CLOSE() GMOD_DLL_EXPORT int gmod13_close( [[maybe_unused]] lua_State* state ) |
| 40 | + |
| 41 | + #define LUA_FUNCTION( name ) int name( [[maybe_unused]] lua_State *state ) |
| 42 | + #define LUA_FUNCTION_STATIC( name ) static LUA_FUNCTION( name ) |
| 43 | + #else |
| 44 | + #define GMOD_MODULE_OPEN() \ |
| 45 | + int gmod13_open__Imp( GarrysMod::Lua::ILuaInterface* LUA ); \ |
| 46 | + GMOD_DLL_EXPORT int gmod13_open( lua_State* L ) \ |
| 47 | + { \ |
| 48 | + return gmod13_open__Imp( L->luabase ); \ |
| 49 | + } \ |
| 50 | + int gmod13_open__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaInterface* LUA ) |
| 51 | + |
| 52 | + #define GMOD_MODULE_CLOSE() \ |
| 53 | + int gmod13_close__Imp( GarrysMod::Lua::ILuaInterface* LUA ); \ |
| 54 | + GMOD_DLL_EXPORT int gmod13_close( lua_State* L ) \ |
| 55 | + { \ |
| 56 | + return gmod13_close__Imp( L->luabase ); \ |
| 57 | + } \ |
| 58 | + int gmod13_close__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaInterface* LUA ) |
| 59 | + |
| 60 | + #define LUA_FUNCTION( FUNC ) \ |
| 61 | + int FUNC##__Imp( GarrysMod::Lua::ILuaInterface* LUA ); \ |
| 62 | + int FUNC( lua_State* L ) \ |
| 63 | + { \ |
| 64 | + GarrysMod::Lua::ILuaInterface* LUA = L->luabase; \ |
| 65 | + LUA->SetState(L); \ |
| 66 | + return FUNC##__Imp( LUA ); \ |
| 67 | + } \ |
| 68 | + int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaInterface* LUA ) |
| 69 | + |
| 70 | + #define LUA_FUNCTION_STATIC( FUNC ) \ |
| 71 | + static int FUNC##__Imp( GarrysMod::Lua::ILuaInterface* LUA ); \ |
| 72 | + static int FUNC( lua_State* L ) \ |
| 73 | + { \ |
| 74 | + GarrysMod::Lua::ILuaInterface* LUA = L->luabase; \ |
| 75 | + LUA->SetState(L); \ |
| 76 | + return FUNC##__Imp( LUA ); \ |
| 77 | + } \ |
| 78 | + static int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaInterface* LUA ) |
| 79 | + |
| 80 | + #define LUA_FUNCTION_DECLARE( FUNC ) \ |
| 81 | + int FUNC( lua_State *L ) |
| 82 | + |
| 83 | + #define LUA_FUNCTION_STATIC_DECLARE( FUNC ) \ |
| 84 | + static int FUNC( lua_State *L ) |
| 85 | + |
| 86 | + #define LUA_FUNCTION_IMPLEMENT( FUNC ) \ |
| 87 | + [[deprecated("Use LUA_FUNCTION_STATIC_MEMBER instead of LUA_FUNCTION_IMPLEMENT.")]] \ |
| 88 | + static int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaInterface* LUA ) |
| 89 | + |
| 90 | + #define LUA_FUNCTION_WRAP( FUNC ) \ |
| 91 | + [[deprecated("Use LUA_FUNCTION_STATIC_MEMBER instead of LUA_FUNCTION_WRAP.")]] \ |
| 92 | + static int FUNC( lua_State *L ) \ |
| 93 | + { \ |
| 94 | + GarrysMod::Lua::ILuaInterface* LUA = L->luabase; \ |
| 95 | + LUA->SetState(L); \ |
| 96 | + return FUNC##__Imp( LUA ); \ |
| 97 | + } |
| 98 | + |
| 99 | + #define LUA_FUNCTION_STATIC_MEMBER( FUNC ) \ |
| 100 | + static int FUNC( lua_State* L ) \ |
| 101 | + { \ |
| 102 | + GarrysMod::Lua::ILuaInterface* LUA = L->luabase; \ |
| 103 | + LUA->SetState(L); \ |
| 104 | + return FUNC##__Imp( LUA ); \ |
| 105 | + } \ |
| 106 | + static int FUNC##__Imp( GarrysMod::Lua::ILuaInterface* LUA ) |
| 107 | + #endif |
| 108 | +#endif |
| 109 | + |
| 110 | +#endif |
0 commit comments