• Garry's Mod 13 Version of RunString() in Binary Modules
    5 replies, posted
With the coming of Garry's Mod 13 came the new headers for binary modules, and now I'm stuck at how to implement this in a binary module. I thought I'd be smart and thought my example below would work but of course, it doesn't as I have no clue what I'm doing with these new headers. If anyone knows (or has) implemented a way to run a string of Lua in a binary module, I'd love to know how. Thanks! [CODE]#include "GarrysMod/Lua/Interface.h" #include <stdio.h> using namespace GarrysMod::Lua; int TestFunction( lua_State* state ) { LUA->PushString("MsgN('Test Function Works!');"); LUA->Call(0, 0); return 1; } GMOD_MODULE_OPEN() { LUA->PushSpecial( GarrysMod::Lua::SPECIAL_GLOB ); LUA->PushString( "TestFunction" ); LUA->PushCFunction( TestFunction ); LUA->SetTable( -3 ); return 0; } GMOD_MODULE_CLOSE() { return 0; } [/CODE]
I already have an idea but, what exactly you need this for? :v:
[QUOTE=Wizard of Ass;40997082]I already have an idea but, what exactly you need this for? :v:[/QUOTE] It might sound redundant as I can also do this in Lua, but I'd like to use it as a base that all my servers can require to allow for easier mysqloo integration (Mainly connecting to the database, and escaping stuff). I'd like to do it in C++ just to get some experience with the language. :dance: [B]EDIT:[/B] And yes, I know I can escape strings with MySQLoo already, I was just throwing out examples.
In GMOD_MODULE_OPEN, push the global table, then get the "RunString" field, create & store a reference to it then push that before the Lua you want to run. Unless you want to directly get the C function that RunString is bound to, in which case I have no idea [editline]11th June 2013[/editline] Although what you're using it for is ridiculous...
The only reason I can think you "needing" this specific function is writing another shitty hack. :v:
[QUOTE=Drakehawke;40997411]In GMOD_MODULE_OPEN, push the global table, then get the "RunString" field, create & store a reference to it then push that before the Lua you want to run. Unless you want to directly get the C function that RunString is bound to, in which case I have no idea [editline]11th June 2013[/editline] Although what you're using it for is ridiculous...[/QUOTE] Works like a charm, thanks! :smile:
Sorry, you need to Log In to post a reply to this thread.