Last active
August 29, 2015 13:56
-
-
Save McSimp/81c5ef860a8a4eb51d0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "CNetMessageRegistration.hpp" | |
#include "CNetMessage.hpp" | |
#include "gm/Lua.hpp" | |
#include "gm/CStateManager.hpp" | |
using namespace GarrysMod::Lua; | |
template <class T, int (T::*F)(CLuaInterface& Lua)> | |
int LuaBindThunk(lua_State* L) | |
{ | |
// TODO: Get instance from userdata | |
T* obj = nullptr; | |
return (obj->*F)(g_StateManager.GetInterface(L)); | |
} | |
class SVC_Print; | |
CMessageClassRegistration<SVC_Print> Registration("svc_Print"); | |
class SVC_Print : public CNetMessage | |
{ | |
SVC_Print() { m_bReliable = false; m_text = nullptr; }; | |
public: | |
void* m_pMessageHandler; | |
const char* m_text; | |
bool WriteHook(bf_write& buffer) | |
{ | |
Msg("Hi there everything!\n"); | |
return Registration.CallOriginalWrite(this, buffer); | |
} | |
int LuaGetText(CLuaInterface& Lua) | |
{ | |
return 0; | |
} | |
static void InitializeLua(CLuaInterface& Lua) | |
{ | |
Msg("svc_Print is being added to Lua!\n"); | |
Registration.Attach(); | |
Lua.SetGlobal("GetText", &LuaBindThunk<SVC_Print, &SVC_Print::LuaGetText>(Lua.GetLuaState())); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment