Jump to content
  • Advertisement
Sign in to follow this  
ClementVidal

Call lua function with "Swiged" parameter... How to ?

This topic is 2555 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everybody,

I'm currently using SWIG 2.0 to allow various classes of my application to be accessible from Lua.
Everything is working fine, and really, SWIG is a GREAT tool but ... i'm facing a problem:

I have a swiged class "CMyClass".
And i want to call a lua function let's say:


function OnPostInfoRequest( myclass )
print( myclass.AFunctionOfCMyClass() )
end

At first i thought it would be enought to use lua_pushlightuserdata and to call the OnPostInfoRequest(), but apparently that's not the case.
If i just do that, when the statement myclass.AFunctionOfCMyClass() is executed, i have a lua error that say that myclass does not have any metatable associated ...
Does anybody know how to achieve that ?
Should i use the SWIG_lua function [font=monospace][size=2]SWIG_NewPointerObj ?[/font]
[font=monospace][size=2]
[/font]
[font=monospace][size=2]Any help is welcome !![/font]
[font=monospace][size=2]
[/font]
[font=monospace][size=2]Thanks![/font]

Share this post


Link to post
Share on other sites
Advertisement
Hi,
C++ code will look like:

myclass * my_class_ptr;
lua_State *L;
....
lua_getglobal(L, "OnPostInfoRequest");

SWIG_NewPointerObj(L, my_class_ptr, SWIG_TypeQuery(L, "myclass*"), 0);

lua_pcall(L, 2, 1, 0) ;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!