Garry's Mod 13 Version of RunString() in Binary Modules

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!

#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;

    LUA->PushSpecial( GarrysMod::Lua::SPECIAL_GLOB );
    LUA->PushString( "TestFunction" );
    LUA->PushCFunction( TestFunction );
    LUA->SetTable( -3 );
    return 0;

    return 0;

I already have an idea but, what exactly you need this for? :v:

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:

EDIT: 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:

Works like a charm, thanks! :smile: