diff --git a/_testing/gmod_testing.lua b/_testing/gmod_testing.lua index 2030f38..9cfdc1f 100644 --- a/_testing/gmod_testing.lua +++ b/_testing/gmod_testing.lua @@ -75,12 +75,12 @@ local code = [[local ret, err = pcall(function() Run = function(name, ...) local args = {...} print("hook.Run called!", name) - for k, v in pairs(args) do - print(v) - end + PrintTable(args) end } + gameevent.Listen("player_spawn") + error("Error handling test") end) diff --git a/source/library_Global.cpp b/source/library_Global.cpp index 1aaca81..912da43 100644 --- a/source/library_Global.cpp +++ b/source/library_Global.cpp @@ -255,6 +255,14 @@ LUA_FUNCTION(RealTime) return 1; } +LUA_FUNCTION(RunConsoleCommand) // ToDo: Finish this. This is not how it should work. +{ + const char* cmd = LUA->CheckString(1); + engine->GMOD_RawServerCommand(cmd); + + return 1; +} + void InitGlobal(ILuaInterface* LUA) { LUA->PushSpecial(SPECIAL_GLOB); @@ -264,6 +272,7 @@ void InitGlobal(ILuaInterface* LUA) Add_Func(LUA, AddConsoleCommand, "AddConsoleCommand"); Add_Func(LUA, AddCSLuaFile, "AddCSLuaFile"); Add_Func(LUA, Global_Msg, "Msg"); + Add_Func(LUA, RunConsoleCommand, "RunConsoleCommand"); Add_Func(LUA, CurTime, "CurTime"); Add_Func(LUA, RealTime, "RealTime"); diff --git a/source/library_engine.cpp b/source/library_engine.cpp index 0a9cbe0..92b270e 100644 --- a/source/library_engine.cpp +++ b/source/library_engine.cpp @@ -29,7 +29,6 @@ CGlobalVars* GlobalVars() return iface_pointer; } -IVEngineServer* engine; LUA_FUNCTION(engine_GetAddons) { PushValue(LUA, GMOD->addons); diff --git a/source/lua_utils.cpp b/source/lua_utils.cpp index c2729c3..e9973d6 100644 --- a/source/lua_utils.cpp +++ b/source/lua_utils.cpp @@ -19,6 +19,7 @@ GarrysMod::Lua::ILuaInterface* Win_CreateInterface() { IFileSystem* filesystem; CGlobalVars* gpGlobal; +IVEngineServer* engine; int interfaces_count = 0; std::unordered_map interfaces; diff --git a/source/lua_utils.h b/source/lua_utils.h index 30c064e..8d6424d 100644 --- a/source/lua_utils.h +++ b/source/lua_utils.h @@ -253,4 +253,5 @@ extern void ShutdownInterface(ILuaThread*); extern std::string ToPath(std::string); extern IFileSystem* filesystem; -extern CGlobalVars* gpGlobal; \ No newline at end of file +extern CGlobalVars* gpGlobal; +extern IVEngineServer* engine; \ No newline at end of file