Sign in to follow this  

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

Recommended Posts

Hello everybody,

I'm currently using [b]SWIG 2.0 [/b]to allow various classes of my application to be accessible from [b]Lua[/b].
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:

[b]function OnPostInfoRequest( myclass )[/b]
[b] print( myclass.AFunctionOfCMyClass() )[/b]

At first i thought it would be enought to use [b]lua_pushlightuserdata [/b]and to call the [b]OnPostInfoRequest()[/b], but apparently that's not the case.
If i just do that, when the statement[b] myclass[/b][b].AFunctionOfCMyClass() [/b] 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 ?[/size][/font]
[font=monospace][size=2]Any help is welcome !![/size][/font]

Share this post

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

myclass * my_class_ptr;
lua_State *L;
lua_getglobal(L, "[b]OnPostInfoRequest[/b]");

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this