Jump to content

Calling Lua table functions from C++ w/params


Rick
 Share

Recommended Posts

I have a Lua table that has functions similar to the App table. I'm able to copy how App is called but I have extra params in my function and not sure how to add those. I'm really not all that familiar with stack type programming.

 

My lua function is:

 

function NoesisHelper:EventRaised(element, event, args)
end

 

where element and event are strings and args is a table.

 

The way I call this without filling in those params is:

 

int stacksize = Interpreter::GetStackSize();

Interpreter::GetGlobal("NoesisHelper");
Interpreter::PushString("EventRaised");

// push the Noesis table onto the stack as "self"
Interpreter::GetTable();
Interpreter::PushValue(-2);

Interpreter::Invoke(1, 1, 0);

// restore the stack size
Interpreter::SetStackSize(stacksize);

What do I do to add 2 string and 1 table param to this function call?

Link to comment
Share on other sites

The first argument of Invoke is the number of arguments. For OO functions, the table itself counts as an argument. So I believe you would just change that first 1 to 2, and the function argument would get passed. You can add as many arguments as you like.

 

You can get the function results back with Interpreter::PopInt() (or something like that...). Lua can actually return multiple values from a function!

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...