Message Board
Message Board > C/C++ > C/C++ and Object Oriented Programming with Lua |
March 17, 2014, 15:20 | |
DoctorN
Whiskered 91 posts |
My question is exactly as the title says. I need some help with C/C++ and Lua. For the longest time, my objects have been hard-coded into the game as classes. Well I can't seem to register a function inside a class to lua. I tried doing a struct, and while I can register static functions from structs to lua, I can't register just regular old structs. I don't really want to do anything complicated, I just need help figuring this out. Thanks
____________ |
# |
March 18, 2014, 16:24 | |
DoctorN
Whiskered 91 posts |
here's an example: Code: typedef struct testobj { bool initialized = false; string name = "testobj"; int x = 0; int y = 0; } testobj; testobj TESTOBJ[5]; int testobj_function( lua_State *L ) { } void testobj_proc( int ID ) { if( TESTOBJ[ID].initialized == false ) { //state object name and it's location printf("%d starting at: %d,%d",TESTOBJ[ID].name.c_str(),TESTOBJ[ID].x,TESTOBJ[ID].y); //prevent initialization from occurring again TESTOBJ[ID].initialized = true; } } How can I register testobj_function and have it communicate only with the ID of it's parents? Know what i'm saying? Thanks ____________ |
# |
March 19, 2014, 21:49 | |
DTM
Earthling! 823 posts |
I have absolutely no idea. I think you better ask on a Lua forum. Remember structs and classes are more or less exactly the same thing. (Except structs default to public:). This probably doesn't help though. I imagine to register a full C++ class for use by Lua you'd have to somehow tell Lua about all available attributes and methods of the class. It's not gonna deduce this by itself. A quick google for "lua register c++ class" finds stuff like this: http://loadcode.blogspot.com/2 … ses-in-lua.html ____________ :o |
# |
Message Board > C/C++ > C/C++ and Object Oriented Programming with Lua