Jump to content

Passing parameters to lua via CallFunction?


Guppy
 Share

Recommended Posts

Entity->CallFunction comes in two flavors, one that seems aimed at collisions and one that passes an Object pointer.

 

I'm not entirely sure how I'm supposed to use this to pass data to the function I'm calling, I can set a void pointer as "userdata" which isn't terribly usefull - the source claims to export it to lua but the documentations says it's not exposed in lua.

 

Is it possible to use this to pass a table to lua? and failing that can I somehow convince CallFunction to pass along the information that I've pushed a table onto the stack?

 

 

Right now I'm resorting to putting the table into a global, which is not really ideal.

 

 

Now I can sidestep using CallFunction by doing

 

Leadwerks::Interpreter::GetGlobal("Player:Test");
lua_pcall(Leadwerks::Interpreter::L, 1, 0, 0);

 

Unfortunately I've no idea what Global to use ( in the above I'm trying to target the Test function inside Player )

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

	bool Entity::CallFunction(const std::string& name, Object* extra)
{
	if (component==NULL) return false;
	bool success = false;

	//Get the component table
	int stacksize = Interpreter::GetStackSize();

	//Get the global error handler function
	int errorfunctionindex = 0;
#ifdef DEBUG
	Interpreter::GetGlobal("LuaErrorHandler");
	errorfunctionindex = Interpreter::GetStackSize();
#endif
	Push();
	Interpreter::GetField("script");
	if (Interpreter::IsTable())
	{
		Interpreter::GetField(name);
		if (Interpreter::IsFunction())
		{
			Interpreter::PushValue(-2);//Push script table onto stack
			if (extra!=NULL)
			{
				extra->Push();
#ifdef DEBUG
				errorfunctionindex = -(Interpreter::GetStackSize()-errorfunctionindex+1);
#endif
				success = Interpreter::Invoke(2,0,errorfunctionindex);
			}
			else
			{
#ifdef DEBUG
				errorfunctionindex = -(Interpreter::GetStackSize()-errorfunctionindex+1);
#endif
				success = Interpreter::Invoke(1,0,errorfunctionindex);
			}
		}
	}
	Interpreter::SetStackSize(stacksize);
	return success;
}

  • Upvote 1

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...