Skip to content

Commit

Permalink
Added RunConsoleCommand + Test gameevent.Listen
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelIT7 committed Apr 4, 2024
1 parent 0c0d19f commit b5e60c4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions _testing/gmod_testing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions source/library_Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down
1 change: 0 additions & 1 deletion source/library_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ CGlobalVars* GlobalVars()
return iface_pointer;
}

IVEngineServer* engine;
LUA_FUNCTION(engine_GetAddons)
{
PushValue(LUA, GMOD->addons);
Expand Down
1 change: 1 addition & 0 deletions source/lua_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ GarrysMod::Lua::ILuaInterface* Win_CreateInterface() {

IFileSystem* filesystem;
CGlobalVars* gpGlobal;
IVEngineServer* engine;

int interfaces_count = 0;
std::unordered_map<double, ILuaThread*> interfaces;
Expand Down
3 changes: 2 additions & 1 deletion source/lua_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,5 @@ extern void ShutdownInterface(ILuaThread*);

extern std::string ToPath(std::string);
extern IFileSystem* filesystem;
extern CGlobalVars* gpGlobal;
extern CGlobalVars* gpGlobal;
extern IVEngineServer* engine;

0 comments on commit b5e60c4

Please sign in to comment.