Firstly you shouldn't really be using the sdk/gmod headers for this.
Styles gave you a very good example on how to do it without the sdk.
Personally, Why not just hook CreateLuaInterface and get a pointer to the client interface when its created?
It's probably been done like this by pretty much everyone, but it works.
it works with only luaL_dostring and none of the interface stuff, but when I call iface->GetLuaState() it crashes with this.
https://i.imgur.com/O3W5mue.png
Crashes
Doesn't crash, and worksCode:#include <Windows.h> #include "Lua/Interface.h" #include "icvar.h" #include "ILuaShared.h" #include "lua_shared.h" using namespace GarrysMod::Lua; GMOD_MODULE_OPEN() { ILuaShared* shared; CreateInterfaceFn factory = Sys_GetFactory("lua_shared.dll"); shared = (ILuaShared*)factory(GMOD_LUASHARED_INTERFACE, NULL); ILuaInterface* iface = shared->GetLuaInterface(State::SERVER); lua_State* istate = iface->GetLuaState(); // Crashes here return 0; } GMOD_MODULE_CLOSE() { return 0; }
Code:#include <Windows.h> #include "Lua/Interface.h" #include "icvar.h" #include "ILuaShared.h" #include "lua_shared.h" using namespace GarrysMod::Lua; GMOD_MODULE_OPEN() { luaL_dostring(state, "print(1)"); return 0; } GMOD_MODULE_CLOSE() { return 0; }
Last edited by tdsx; 01-14-2015 at 09:58 PM.
why are you still doing thissssss
your vtable is probably wrongCode:class ILuaInterface { public: void *vtable; public: lua_State *L; };
also you don't have to make it a gmodule with GMOD_MODULE_OPEN and shit, all you have to do is require it and it should automatically call DllMain
ah, I see now. that fixed it. I remember you telling me something about the state being at a certain index in the interface. I put the stuff in GMOD_MODULE_OPEN because I wanted to show that the normal lua state worked, but whatever, it's okay now.
final code - LuaInterface.h
mainCode:namespace GarrysMod { namespace Lua { class ILuaInterface { public: void *vtable; public: lua_State* state; }; } }
sorry for being idiot. now I can finally work on other shit in this module.Code:#include <Windows.h> #include "Lua/Interface.h" #include "icvar.h" #include "ILuaShared.h" #include "lua_shared.h" using namespace GarrysMod::Lua; void Initialize() { ILuaShared* shared; CreateInterfaceFn factory = Sys_GetFactory("lua_shared.dll"); shared = (ILuaShared*)factory(GMOD_LUASHARED_INTERFACE, NULL); lua_State* state = shared->GetLuaInterface(State::SERVER)->state; luaL_dostring(state, "print(1)"); } BOOL APIENTRY DllMain(HANDLE hModule, DWORD Reason, LPVOID lpReserved) { if (Reason == DLL_PROCESS_ATTACH) { Initialize(); return TRUE; } }
how do i get the gary_state* ?????
maybe because you're counting the constructor, but what i've heard everyone is smarter than meep so you should listen to him
i find it funny you make fun of me yet still can't answer simple questions about c++
this isn't the best way - GetLuaInterface is one of the more bad ways to get the CLuaInterface. The best way is to hook it on creation and store it in your own array of CLuaInterface pointers.
that's exactly what he said before, nice job repeating the same thing he said before he gave out an alternative solution
you really are not being helpful
yeah like i'd answer your kindergarten questions just to make you feel better
dream on nerd