Were do I put this wrapper? [Resolved]
Posted: Fri Nov 04, 2011 11:20 pm
I have a class ( WSL::Member_Components::Lightning_Sprite ). The inheritance for it goes
I wrote the following wrapper for it:
In one of the classes in my framework I have the following code:
Basically it registers a global with Lua (a global Lightning_Sprite to be exact).
Now, I know the wrapper and this code is good because I got it to work before, but I had to put the wrapper in the constructor of my Positional class ( the class the code above is from ) and multiple instantiation did not like that very much. So, I have tried to put this wrapper all over the place and it just keeps being stubborn, I either get compiler errors or when I do the line above I get a unreferenced pointer and the IDE brings me either to class_registry.hpp or class_cache.hpp. PLEASE HELP!
Thanks for reading
P.s I know I can sometimes have trouble getting my point across if any clarification is needed please let me know.
-----EDIT-----:
FIXED!
I was half asleep when I wrote this but I will explain what happened so anyone with this problem can know.
I was reconstruction the lua_State in every .obj file so when I made my wrapper it was being allocated to a different lua stack then the file was being run in.
Here is the solution. Make a pointer to the lua state in main or whatever then pass it into the object were the script is going to be run and do the following code:
Code: Select all
Render_Functonal -> Render_Base <T> -> SFMLType<sfmlType> -> Lightning_Sprite
Code: Select all
//I open luabind before I write this.//
luabind::module( WSL::Scripting::Lua.State )[
luabind::class_<WSL::Member_Components::Rendering_System::Base::Render_Functonal>( "RenderFunctonal" )
.def( luabind::constructor<>() )
];
luabind::module( WSL::Scripting::Lua.State )[
luabind::class_<WSL::Member_Components::Rendering_System::Base::Render_Base<sf::Sprite>, WSL::Member_Components::Rendering_System::Base::Render_Functonal>( "RenderBase" )
.def( luabind::constructor<>() )
];
luabind::module( WSL::Scripting::Lua.State )[
luabind::class_<WSL::Member_Components::Rendering_System::Base::SubBase::SFMLType<sf::Sprite>, WSL::Member_Components::Rendering_System::Base::Render_Base<sf::Sprite>>( "SFMLType" )
.def( luabind::constructor<>() )
];
//Just the rotate method because im still testing.
luabind::module( WSL::Scripting::Lua.State )[
luabind::class_<WSL::Member_Components::Lightning_Sprite, WSL::Member_Components::Rendering_System::Base::SubBase::SFMLType<sf::Sprite> >( "Lightning_Sprite" )
.def( luabind::constructor<>() )
.def( "Rotate", &WSL::Member_Components::Lightning_Sprite::Rotate )
];
Code: Select all
luabind::globals( WSL::Scripting::Lua.State )[ "sprite" ] = spr[0].MakePointer( refrence[0] );
Now, I know the wrapper and this code is good because I got it to work before, but I had to put the wrapper in the constructor of my Positional class ( the class the code above is from ) and multiple instantiation did not like that very much. So, I have tried to put this wrapper all over the place and it just keeps being stubborn, I either get compiler errors or when I do the line above I get a unreferenced pointer and the IDE brings me either to class_registry.hpp or class_cache.hpp. PLEASE HELP!
Thanks for reading
P.s I know I can sometimes have trouble getting my point across if any clarification is needed please let me know.
-----EDIT-----:
FIXED!
I was half asleep when I wrote this but I will explain what happened so anyone with this problem can know.
I was reconstruction the lua_State in every .obj file so when I made my wrapper it was being allocated to a different lua stack then the file was being run in.
Here is the solution. Make a pointer to the lua state in main or whatever then pass it into the object were the script is going to be run and do the following code:
Code: Select all
//I have a class containing my lua pointer.//
//I also have a singleton with a pointer to the container.//
luabind::globals( engine->lua->State )[ "sprite" ] = &mySprite;