diff --git a/dlls/gslua.cpp b/dlls/gslua.cpp index 82fc9d8..948e88c 100755 --- a/dlls/gslua.cpp +++ b/dlls/gslua.cpp @@ -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; } diff --git a/dlls/gslua.h b/dlls/gslua.h index 3807ee1..f723b13 100755 --- a/dlls/gslua.h +++ b/dlls/gslua.h @@ -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); diff --git a/projects/vs2010/hldll.vcxproj b/projects/vs2010/hldll.vcxproj index 94364cb..481eee3 100644 --- a/projects/vs2010/hldll.vcxproj +++ b/projects/vs2010/hldll.vcxproj @@ -58,7 +58,7 @@ Level3 Disabled - WIN32;_DEBUG;_WINDOWS;QUIVER;VOXEL;QUAKE2;VALVE_DLL;CLIENT_WEAPONS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;QUIVER;VOXEL;QUAKE2;VALVE_DLL;CLIENT_WEAPONS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true ..\..\dlls;..\..\engine;..\..\common;..\..\pm_shared;..\..\game_shared;..\..\public;%(AdditionalIncludeDirectories) MultiThreadedDebug