-
Member
[3.3.5][c++][Question]
Hi everyone, i trying to register own lua function to the game by:
Code:
int luafunction() {
return 2+2;
}
FramescriptRegister("mynewluafunction", (int)luafunction);
After calling /dump mynewluafunction() in game i have
PHP Code:
Dump: value=mynewluafunction()
[1]=<function [DevTools_Dump]>,
[2]=value,
[3]=<function>,
[4]=<function [DevTools_Dump]>
instead of returning 4
Also tryed
Code:
char* luafunction() {
return "test";
}
it returns
HTML Code:
Dump: value=mynewluafunction()
empty result
I feels that question is very stupid but i'm missing something...
Last edited by Borg333; 08-05-2022 at 04:31 AM.
-
Thats not how lua works.
You need to push return values onto the lua stack. The return value of your function is the amount of return values pushed onto the stack.
Programming in Lua : 26.1
"Threads should always commit suicide - they should never be murdered" - DirectX SDK
-
Post Thanks / Like - 2 Thanks
aeo,
Borg333 (2 members gave Thanks to xalcon for this useful post)
-
Member
Finally someone added all the proper information to figure out a lua problem. Far too many miss the php and html code
-
Member
[answer]
Thanks! It works by
Code:
int luafunction(int state) {
FrameScriptPushNumber(state, 7); // we want to get 7 as result
return 1; // number of result to be returned
}
HTML Code:
Dump: value=mynewluafunction()
[1]=7
-
Member
I have one missunderstading.
I trying to get arg value by
Code:
inline auto FrameScript_ToNumber(int Lstate, int arg)
{
return ((double(__cdecl*)(int, int))0x0084E030)(Lstate, arg);
}
always return 0, if i checks the arg by FrameScript_IsNumber, it can read and return 1 if it is a number, athoerwise 0
Code:
inline auto testint(int Lstate, int arg)
{
double arg = FrameScript_ToNumber(Lstate, 1); //always 0
return 1; //return arg as argument from call
}
on return 1, i see my arg, but how can i extract it from argument from call, i cant understand
-------------------------------------------
Nvm, its worked, don't know why it didn't work before
Last edited by Borg333; 08-08-2022 at 03:11 AM.