LUA Passing a variable from C++ to Lua and..

JMW

Aspiring Addon Developer
Joined
Aug 5, 2008
Messages
611
Reaction score
52
Points
43
Location
Happy Wherever
Someone please put me out of my misery.

How do I call a Lua function from C++ ? and...
Specifically, I want to pass my variable "altm" into the stock Lua Script "aap.lua" value "alt", from my routine in .dll
I've read multiple articles, cut n pasted for hours, but to no avail.
Does this resemble anything that would do it?
Code:
int ShuttlePB::clbkGeneric (int msgid, int prm, void *context)
{
switch (msgid) {
case VMSG_LUAINTERPRETER:
	lua_State *L = (lua_State*)context;
	
luaL_dofile (L, "Script\\35B\\aap.lua");
lua_pcall(L, 0, LUA_MULTRET, 0);

lua_getglobal(L, "alt_ap (alt)");
lua_pushnumber(L, 500);   // altm <---THE VALUE I WANT TO PASS
lua_pcall(L, 1, 1, 0);
lua_pop(L,1);
    
return VMSG_LUAINTERPRETER;
	}
    return 0;
}

Showing my ignorance of Lua (and other things) does the function alt_ap have to be called as well or does it run when aap.lua is loaded? If so, how?
:sos:
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,665
Reaction score
2,386
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Someone please put me out of my misery.

For calling functions from C...

First you need to push the function reference on the stack, then the arguments. Use no signature for the function, only the name alt_ap should be enough in Lua.


Everything looks right there.

Luckily I have a Lua book from my old university days for such problems...
 
Last edited:

JMW

Aspiring Addon Developer
Joined
Aug 5, 2008
Messages
611
Reaction score
52
Points
43
Location
Happy Wherever
Thanks Urwumpe but it doesn't work...........
Where else can I look?
I don't have to change the script file "aap" do I? :hmm:
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,665
Reaction score
2,386
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Have you tested if the aap.lua has been loaded into the context and the functions are available?
 

JMW

Aspiring Addon Developer
Joined
Aug 5, 2008
Messages
611
Reaction score
52
Points
43
Location
Happy Wherever
Well the script "warning" text appears in the Terminal mfd and it works.
How can I tell if the functions are available?
 

BEEP

Addon Developer
Addon Developer
Joined
Apr 5, 2008
Messages
153
Reaction score
15
Points
18
I don't know if a such simple advice would help you, but if I were you I´d edit the aap.lua inserting some debug lines such as..

--********DEBDEBDEB**********
oapi.dbg_out('The value of my variable is now:'..myvariable)
--********DEBDEBDEB**********

or...

function myfunction(itsvariable)

--********DEBDEBDEB**********
oapi.dbg_out('I have entered myfunction now!')
--********DEBDEBDEB**********
.
.
.
end



If things get more complicated and you need more report lines you can use a debug report file instead of oapi.dbg_out().

Rgds

Beep
 
  • Like
Reactions: JMW
Top