[LUA/C] Wie erstelle ich von Bmax aus Klassen?
Übersicht

![]() |
klinBetreff: [LUA/C] Wie erstelle ich von Bmax aus Klassen? |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hallo leute,
stehe wiedermal vor einem Problem und ohne lösung. Und zwar, möchte ich von BlitzMax aus eine LUA Klasse erstellen. Habe sogar nen C Code gefunden: Code: [AUSKLAPPEN] static int newSprite(lua_State *L)
{ int n = lua_gettop(L); // Number of arguments if (n != 4) return luaL_error(L, "Got %d arguments expected 4", n); // Allocate memory for a pointer to to object Sprite **s = (Sprite **)lua_newuserdata(L, sizeof(Sprite *)); double x = luaL_checknumber (L, 1); double y = luaL_checknumber (L, 2); double dir = luaL_checknumber (L, 3); double speed = luaL_checknumber (L, 4); *s = new Sprite(Point2(x, y), dir, speed); lua_getglobal(L, "Sprite"); // Use global table 'Sprite' as metatable lua_setmetatable(L, -2); return 1; } // Show registration of class static const luaL_Reg gSpriteFuncs[] = { // Creation {"new", newSprite}, {"position", position}, {"nextPosition", nextPosition}, {"setPosition", setPosition}, {"render", render}, {"update", update}, {"collision", collision}, {"move", move}, {"accelerate", accelerate}, {"rotate", rotate}, {NULL, NULL} }; void registerSprite(lua_State *L) { luaL_register(L, "Sprite", gSpriteFuncs); lua_pushvalue(L,-1); lua_setfield(L, -2, "__index"); } Jedoch weiß ich nicht, wie ich das Code: [AUSKLAPPEN] // Show registration of class
static const luaL_Reg gSpriteFuncs[] = { // Creation {"new", newSprite}, {"position", position}, {"nextPosition", nextPosition}, {"setPosition", setPosition}, {"render", render}, {"update", update}, {"collision", collision}, {"move", move}, {"accelerate", accelerate}, {"rotate", rotate}, {NULL, NULL} }; in Bmax umsetzten soll. Weiß jemand wie das geht? THX MFG Klin |
||
![]() |
BtbN |
![]() Antworten mit Zitat ![]() |
---|---|---|
Das Modul BRL.Maxlua ist dir bekannt? Damit sollte sich das ohne große Probleme und ohne hantieren mit den lowlvl-Lua-Funktionen bewerkstelligen lassen.
Edit: Genau genommen reicht dafür die Funktion LuaRegisterObject. Lies einfach mal die doks zu dem Modul. |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group