so i want to make something that will get the users steamid from the player argument that comes with the 'PlayerInitialSpawn' hook however it isnt going as straight forward as i hoped.
everytime the hook gets called i get this error:
https://files.facepunch.com/forum/upload/465720/b1817a17-b90f-4df5-8379-602cd7d41460/image.png
my code is:
https://files.facepunch.com/forum/upload/465720/19625760-80fa-4ea9-bfa3-30a61ad529e5/image.png
any help is appreciated, im still trying to figure out how the entire lua stack works.
Why not just use LUA. (I don't know why you'd make a module, really useless if its for other player use, if its just for practice then...
I am a C noob, but everythings worth a try.
Found here: https://forum.facepunch.com/f/gmoddev/mntw/Dealing-with-hooks-in-a-binary-Module/1/
Look over that for reference.
Also you're issue resides where your adding / creating the hook.
garrysmod/hook.lua at master · Facepunch/garrysmod · GitHub
Potential invalid Userdata? I don't understand C, but from what I found it shouldn't be hard.
no the hook is being called, by what i can tell at least, since i have done a bit of testing such as adding a print before the main body of the hook is ran, and it gets run, so the hook does get called, i also made a quick function to print the stack and i do get the argument correctly as it says an Entity is in slot 1, witch is where the arguments are parsed (1, 2, 3, 4 . . . ) and everything under 0 is my local stack (per say).
as for why im doing this in a module, because i wanna learn how these things work before i do some big things with them, that and it would be cool to create a game mode entirly in c/c++.
Here's my stack function:
static void PrintStack(lua_State* L)
{
int i;
int top = lua_gettop(L);
L->luabase->MsgColour(Color(255,255,0), "Stack:\n");
for (i = 1; i <= top; i++) {
GetGlobal("tostring")
lua_pushvalue(L, i);
lua_call(L, 1, 1);
L->luabase->MsgColour(WINC_BRIGHT_GREEN, "\t%d\t=\t%s\n", i,lua_tostring(L,-1));
lua_pop(L, 1);
}
L->luabase->Msg("\n");
return;
}
Also why you set function with lua_State?
GMOD has snippets for interface
GMOD_MODULE_OPEN
GMOD_MODULE_CLOSE
LUA_FUNCTION
like i said, i got it working and you can see that i changed the check in the code, as for LUA_FUNCTION didn't check what it did, so i just went for a straight up delegate function instead of using the macro to make it
With this macro you don't need to put your L->luabase macro everywhere.
It will be as an argument for the function.
LUA_FUNCTION(func)
{
LUA->PushString("mystring");
return 0;
}
yea i swaped it out now thnx, but im running into another issue now, i cant use MsgC properly, i have it set up to where i send a table via the net library but i cant set keys in tables to numeric, and MsgC doesn't take string keys..... so yea, i need to either figure out a way of setting keys as numeric or make a wrapper that partialy calls lua functions to reset keys to there numerical counterpart
Open LuaBase.h and look for all function you can use
man, im starting to like stack programming over usual lua programming, i might make the rest of my lua stuff in c/c++
That file contains ILuaBase functions
yea, i know, >-> if i didn't have it i wouldnt have any basis to communicate with lua, im still in the process of reading over what each of the functions do from both the tooltip in the file, as well as any online sources
that and it would be cool to create a game mode entirly in c/c++.
this is really dumb, you are just calling lua functions from c++?
Just in case, that will not increase the perfomance.
GMod Lua API is indirect. So sometimes compiled lua will run faster
thats my end goal but im thinking of trying to make it more intergrated within gmod so that i dont have to call apon the lua stack for everything.
Please do not insult C by calling it C++ and not distinguishing between the two :V
so it clerify why doing a game mode fully in c/c++ would be a good idea, or just in general making addons in c/c++,
heres an example for something that is done best in c/c++ and worse in pure lua
https://files.facepunch.com/forum/upload/465720/7acdcd35-88d6-4127-9d9b-190f91479ee1/image.png
you don't want to do something processing heavy in a language like lua, since it is all contained on the stack and has a lot of header info, with c/c++ you can directly call apon the values AND using a few pointer techniqes you can cleanly and quickly scan the entire input string, without having to copy the string several times.
I still fail to really find excuses to choose one over the other besides portability, and guess which one wins, maybe if you're looking to do stuff that you're not allowed to do with lua, like sql library, sockets, stuff like that, benefits are just...Damn small
While doing these Lua to C remakes, make sure to benchmark the speed of the function made in C and the same in Lua
Sorry, you need to Log In to post a reply to this thread.