On Fri, Oct 10, 2008 at 9:25 AM, Scott Kirkpatrick <[EMAIL PROTECTED]> wrote: > I'm new to embedding a scripting engine in another application but I can > follow how to call a Lua function from a wxWidgets application and how > to pass data to it and get data back. I see that wxLua gives me the > ability to do that with wxWidgets objects. However, I haven't been able > to figure out how to do that with my own classes. > > I have a wxList of my custom objects that I need to pass to a Lua > function and get a return value. I've looked at the wxLuacan > application and realize that I have to do something with bindings but > for the life of me, I can't figure out how to go about it. I haven't > been able to locate a tutorial on the subject either. Can somebody give > me a step-by-step for doing this?
The best way to see how to run code is to check the binding functions in modules/wxbind/src, constructors will create new objects and the others will get an object from Also see here: http://www.lua.org/pil/25.2.html Warning, untested code. Example: Call this Lua function from C. function PrintwxPoint(pt) print(pt.x, pt.y) end C code would be (see wxLua_wxPoint_constructor in modules/wxbind/src/wxcore.gdi.cpp) wxLuaState wxlState(myEventHandlerThatHandles_wxEVT_LUA_PRINT); wxlState.RunString("function PrintwxPoint(...."); lua_State* L = wxlState.GetLuaState(); lua_getglobal(L, "PrintwxPoint"); // Lua func on stack if (Lua should own object we push) wxPoint* pt= new wxPoint(1, 2); // add to tracked memory list wxluaO_addgcobject(L, (void*)pt, new wxLua_wxObject_wxPoint((wxPoint*)pt)); // push the constructed class pointer wxluaT_pushuserdatatype(L, pt, wxluatype_wxPoint); else wxPoint pt(1,2); // must exist for the life of the Lua function wxluaT_pushuserdatatype(L, &pt, wxluatype_wxPoint); end int status = wxlState.LuaPCall(1, 0); // call PrintwxPoint w/ one param Hope this helps, John ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ wxlua-users mailing list wxlua-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wxlua-users