_tommo_ wrote:An advice using table as indexed arrays:
Thing about that is that it's not explicit, and it is specifically ordered. The user may want a default size, or a position before a size, or an auto-calculated size, and so on.
You could also make those callbacks more elegant wrapping the Lua Stack to a C++ class; here's how i call my callbacks (wich are the most important part of the scripting in my game):
Code: Select all
//get the Lua Manager
sm = GameServer::get<ScriptManager>();
//call object construction callback, named typeName+"_onCreation()"
sm->luaLoadFunction( typeName + "_onCreation");
sm->luaLoadParam<InkObject*>( "Object", this ); //SELF
sm->luaLoadParam( position.x ); //X
sm->luaLoadParam( position.y ); //Y
sm->luaLoadParam<Trace*>("Trace", t); //TRACE
sm->luaCallFunction( 0 ); //No results
Using luabind:
Code: Select all
// L is your lua_State
luabind::call_function<void>(L, typeName + "_onCreation", this, position.x, position.y, t);
So, you can call a callback of any shape, without using any crazy boost things, but only const char* + some functions

And these are all iinline functions!
Same with luabind. What I was talking about was this:
Code: Select all
// C++ widget callback
void scrolledCallback(const gui::event &e)
{
std::cout << "scrolled scrollbar "" << e.caller.name() << ""\n";
}
// register as onScroll
someScrollbar.callback("onScroll", boost::bind(&scrolledCallback, _1));
That's pretty easy C++.
But what if you wanted Lua to be able to register Lua-based callbacks for the widgets? Obviously you can't use boost::bind(the_lua_function)

. But it
can be done - you need a proxy C++ widget callback that receives a Lua object (luabind::object) which corresponds to the Lua widget callback. Then, using boost::bind, you'd bind the widget's callback to this proxy C++ callback, use _1 for the event (widget passes it), and pass the Lua function for the second parameter. The widget doesn't know that it's now calling a Lua callback
PS: yes, i find Boost really bloated...
Have you actually tried it and used it? I used to think it was really bloated and unnecessary, too - until I started using it. This thing is full of goodness and nothing else. And it's all headers - you don't need to compile anything (unless you use the platform-specific things, like Boost.Filesystem, which needs to be compiled first).