Jump to content

can i call a lua script function, attached to an object from C++?


Recommended Posts

Posted

i have many objects with scripts attached

if i get one of them via collision or ray pick, can i call a function declared inside the entity's script?

 

something like

pickinfo.entity.script.Hit(), if Hit is defined inside the script

 

thank's in advance

 

Juan

Paren el mundo!, me quiero bajar.

Posted

Unless Josh made this easier in Leadwerks, you probably can but it might be ugly. I know Josh has some Lua wrappers exposed.

 

Below is a starting point to see how a "normal" lua function is called. Look at the Lua function here and you should see some similar ones in Leadwerks that Josh wrapped up and you might be able to work it out. If you do, make a nice easy function for the rest of us smile.png

 

Since script functions are table functions the call will be different. You probably have to push the table onto the stack or something like that before making the call.

 

http://www.lua.org/pil/25.2.html

 

It would be really nice if Josh made this really easy though.

 

Something like:

 

pickinfo.entity->script->CallFunction("Hit");

Posted

thank's i have to seriously start studying c++ and lua

 

by the moment i have to evade call a script function from c++, till i get older!

 

 

 

thank's again

Paren el mundo!, me quiero bajar.

Posted

Not sure. I am on the go, but you could try if

entity->SetString("yourVar", "yourvalue");

 

Exists in the API and set it before calling the function

Then read that value in the script.

Posted

Yeah, that's what I was thinking, but limited to string/number that way vs tables/objects, but would probably work for a good number of situations although a little hacky.

Posted

I wonder if we can combine CallFunction() with pushing things on the stack in Lua if that would pass the data to the function like normal parameters. Will have to test when I have time.

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.

×
×
  • Create New...