I can't remember what I did, but it was something cool
parent
c15309a5a0
commit
fd9603ce3f
|
@ -13,21 +13,20 @@
|
|||
extern lua_State *g_L;
|
||||
extern BOOL g_bLuaInitialized;
|
||||
|
||||
static const luaL_Reg gsLib_METHODS[] = {
|
||||
{ "Print_Console", LUA_PrintConsole },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
typedef enum
|
||||
typedef enum gsLuaType
|
||||
{
|
||||
LTYPE_INT,
|
||||
LTYPE_STR
|
||||
LTYPE_STRING,
|
||||
LTYPE_FLOAT,
|
||||
LTYPE_FUNC
|
||||
} gsLuaType;
|
||||
|
||||
typedef union
|
||||
typedef union gsLuaGlobal
|
||||
{
|
||||
int i;
|
||||
const char *str;
|
||||
char const *str;
|
||||
float f;
|
||||
lua_CFunction fn;
|
||||
} gsLuaGlobal;
|
||||
|
||||
typedef struct gsLuaRegGlobal
|
||||
|
@ -37,13 +36,19 @@ typedef struct gsLuaRegGlobal
|
|||
gsLuaType type;
|
||||
} gsLuaRegGlobal;
|
||||
|
||||
static gsLuaRegGlobal const gsLib_GLOBALS[] = {
|
||||
{ "at_notice", at_notice, LTYPE_INT },
|
||||
{ "at_console", at_console, LTYPE_INT },
|
||||
{ "at_aiconsole", at_aiconsole, LTYPE_INT },
|
||||
{ "at_warning", at_warning, LTYPE_INT },
|
||||
{ "at_error", at_error, LTYPE_INT },
|
||||
{ "at_logged", at_logged, LTYPE_INT },
|
||||
enum
|
||||
{
|
||||
LF_PRINT_CONSOLE = 6
|
||||
};
|
||||
|
||||
static gsLuaRegGlobal gsLib_GLOBALS[] = {
|
||||
{ "at_notice", at_notice, LTYPE_INT },
|
||||
{ "at_console", at_console, LTYPE_INT },
|
||||
{ "at_aiconsole", at_aiconsole, LTYPE_INT },
|
||||
{ "at_warning", at_warning, LTYPE_INT },
|
||||
{ "at_error", at_error, LTYPE_INT },
|
||||
{ "at_logged", at_logged, LTYPE_INT },
|
||||
{ "Print_Console", 0, LTYPE_FUNC },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
|
@ -53,11 +58,12 @@ static gsLuaRegGlobal const gsLib_GLOBALS[] = {
|
|||
|
||||
void LuaInit(void)
|
||||
{
|
||||
gsLib_GLOBALS[LF_PRINT_CONSOLE].value.fn = LUA_PrintConsole;
|
||||
|
||||
g_L = luaL_newstate();
|
||||
g_bLuaInitialized = TRUE;
|
||||
ALERT(at_console, "[HLua] Lua initialized.\n");
|
||||
|
||||
LuaRegisterFunctions();
|
||||
LuaRegisterGlobals();
|
||||
|
||||
if(luaL_dostring(g_L, "Print_Console(at_console, \"[HLua::Lua] Initialization success!\");") == TRUE)
|
||||
|
@ -77,7 +83,7 @@ void LuaQuit(void)
|
|||
|
||||
void LuaCheckNull(void const *vpToCheck)
|
||||
{
|
||||
if (vpToCheck == NULL)
|
||||
if(vpToCheck == NULL)
|
||||
{
|
||||
LuaError("[HLua] Null pointer exception!\n");
|
||||
}
|
||||
|
@ -148,21 +154,6 @@ void LuaParseScripts(void)
|
|||
|
||||
// --- Binded lua functions and globals ---
|
||||
|
||||
void LuaRegisterFunctions(void)
|
||||
{
|
||||
int i;
|
||||
ALERT(at_console, "[HLua] Registering functions.\n");
|
||||
|
||||
for(i = 0; i < MAX_LUA_LIB_FUNCS; i++)
|
||||
{
|
||||
if(gsLib_METHODS[i].name == NULL && gsLib_METHODS[i].func == NULL) break;
|
||||
|
||||
lua_register(g_L, gsLib_METHODS[i].name, gsLib_METHODS[i].func);
|
||||
}
|
||||
|
||||
ALERT(at_console, "[HLua] Register success, got %d functions.\n", i);
|
||||
}
|
||||
|
||||
void LuaRegisterGlobals(void)
|
||||
{
|
||||
int i;
|
||||
|
@ -175,7 +166,9 @@ void LuaRegisterGlobals(void)
|
|||
switch(gsLib_GLOBALS[i].type)
|
||||
{
|
||||
case LTYPE_INT: lua_pushnumber(g_L, gsLib_GLOBALS[i].value.i); break;
|
||||
case LTYPE_STR: lua_pushstring(g_L, gsLib_GLOBALS[i].value.str); break;
|
||||
case LTYPE_STRING: lua_pushstring(g_L, gsLib_GLOBALS[i].value.str); break;
|
||||
case LTYPE_FLOAT: lua_pushnumber(g_L, gsLib_GLOBALS[i].value.f); break;
|
||||
case LTYPE_FUNC: lua_pushcfunction(g_L, gsLib_GLOBALS[i].value.fn); break;
|
||||
default: LuaError("[HLua] Invalid type in global initializer!\n"); return;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
void LuaInit(void);
|
||||
void LuaQuit(void);
|
||||
void LuaCheckNull(void const *vpToCheck);
|
||||
void LuaRegisterFunctions(void);
|
||||
void LuaRegisterGlobals(void);
|
||||
void LuaParseScripts(void);
|
||||
void LuaRunScript(char *szFilename);
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;QUIVER;VOXEL;QUAKE2;VALVE_DLL;CLIENT_WEAPONS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;QUIVER;VOXEL;QUAKE2;VALVE_DLL;CLIENT_WEAPONS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
||||
<AdditionalIncludeDirectories>..\..\dlls;..\..\engine;..\..\common;..\..\pm_shared;..\..\game_shared;..\..\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
|
|
Loading…
Reference in New Issue