#include "lugre_prefix.h"
#include "lugre_luabind_direct.h"
// some c++ class that isn't aware of lua, can also be in a separate file of course
class cSomeThingy { public:
cSomeThingy ();
~cSomeThingy ();
int SomeMethod (int a);
}
// luabinding class
class cLuaBind_SomeThingy : public cLuaBindDirect<cSomeThingy> { public:
// methods
virtual void RegisterMethods (lua_State *L) {
LUABIND_QUICKWRAP_STATIC(CreateSomeThingy, {
return CreateUData(L,new cSomeThingy());
});
LUABIND_QUICKWRAP(Destroy, {
delete &GetSelf(L);
});
LUABIND_QUICKWRAP(SomeMethod, {
// index of the parameter, 1 is the implicit this/self/object handle, 2 = first parameter, 3 = second parameter....
return PushInt(L, GetSelf(L).SomeMethod( ParamInt(L,2) ) );
});
}
virtual const char* GetLuaTypeName () { return "somelib.somethingy"; }
};
// this function has to be called once during lua init
void LuaRegisterSomeClasses (lua_State* L) {
cLuaBindDirect<cSomeThingy>::GetSingletonPtr(new cLuaBind_SomeThingy())->LuaRegister(L);
}
/*
lua example code :
local o = CreateSomeThingy()
o:SomeMethod(5)
o:Destroy()
*/
LUABIND_QUICKWRAP(SomeOtherMethod, { print("hello world\n"); });
StefanP.MUC {l Wrote}:What alternative would you suggest?
MyEmail {l Wrote}:Boost, which IMHO is the worst thing since Vista
charlie {l Wrote}:Would be great if you could elaborate. (As a non-C++ programmer I've not ever had to deal with boost.)
StefanP.MUC {l Wrote}:By the way, a question, possibly directed directly at oln, about the threading in OD (as this is also in discussion and planning currently): Has the script engine to be multi-threaded? What features does it need to have in this context?
It seems that only AngelScript is natively fully multi-threaded (that also allows to control the different threads manually, etc).
Lua needs addons, squirrel is not fully multi-theadable (or also only with addon).
MyEmail {l Wrote}:Meh, thread-safe games is a piece of cake if you do it right. Put the game-logic in one thread, rendering in another, pathfinding in another, physics in another, etc. It ends up having very nice performance. If not done right, it can be very detrimental to a project.
svenskmand {l Wrote}:That will not scale well, what do you do when you have 32 or 64 or even more processors? The way we are going to do it, as I mention above, will be completely scaleable and use all available processors as long as the number of processors is at most the number of game objects, and if you have more game performance will not be an issue for you.
Users browsing this forum: No registered users and 1 guest