LUAScript - Tables / Objekte an Script senden?
Übersicht

SlasHeRBetreff: LUAScript - Tables / Objekte an Script senden? |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Wie kann ich denn in BlitzMax mit dem LUAScript Modul
ein Objekt übergeben, das ich selbst erstellt habe. Z.b. nen Player Objekt mit x,y,z, name Wo ich dann im Script mit myPlayer.name ="Player1" myPlayer.x = x+1 .... drauf zugreifen könnte? Meine Recherche in der Documentation hat ergeben, dass man dazu Tables in LUA verwendet. myPlayer.name ist äquivalent zu myPlayer["name"] Dann habe ich noch etwas mit C-Libs gefunden, die man nach LUA importieren kann, und dass es Sinn machen wuerde, so seinen Code zu gestalten (in C).. Verwirrt? - Ich auch. Hoffe es gibt jemanden, der damit schon Erfahrung hat und uns weiter helfen kann. |
||
![]() |
YellowRiderEhemaliger Admin |
![]() Antworten mit Zitat ![]() |
---|---|---|
~VERSCHOBEN~ Dieser Thread passte nicht in das Forum, in dem er ursprünglich gepostet wurde. mfg YellowRider |
||
SlasHeR |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Dann muss ich den Titel des anderen Forums falsch verstanden haben.
" Module - "Fragen zu BlitzMax Modulen und Präsentationen von BlitzMax-Modulen" LUASCRIPT ist doch ein blitzmax modul, oder nicht? Egal, wäre dennoch nett, wen jemand nen tip hat. |
||
Dreamora |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Ja
Aber es ist keine Frage zu einem Modul sondern zur Verwendung eines solchen bzw. zu einer anderen "Sprache" |
||
Ihr findet die aktuellen Projekte unter Gayasoft und könnt mich unter @gayasoft auf Twitter erreichen. |
SlasHeR |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
jaja... will das hier auch garnicht ausdiskutieren ![]() Suche doch nur Hilfe von Euch! ![]() |
||
Dreamora |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
http://www.blitzwiki.org/index.php/Lua_Tutorial
http://www.blitzbasic.com/Comm...opic=47321 |
||
Ihr findet die aktuellen Projekte unter Gayasoft und könnt mich unter @gayasoft auf Twitter erreichen. |
![]() |
rema |
![]() Antworten mit Zitat ![]() |
---|---|---|
OT: da kann ich SlasHeR nur recht geben. Die Beschreibung des Forum Module kann man missverstehen. Eigentlich gehts um selbst geschriebene Module. Jedes Modul dass dann integriert wird ist dann ein Teil von BlitzMax und somit gehört dann die Frage zu Allgemein oder Beginner-Corner... | ||
SlasHeR |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Dreamora:
Danke für den Link, das wiki kannte ich noch nicht. allerdings gabs dazu leider nichts dort. Ich habe mir nochmal die Doku von LUA direkt reingefahren (so wie auf dem Link später auch verwiesen wird) Zitat: 3.11 - Manipulating Tables Tables are created by calling the function void lua_newtable (lua_State *L); This function creates a new, empty table and pushes it onto the stack. To read a value from a table that resides somewhere in the stack, call void lua_gettable (lua_State *L, int index); where index points to the table. lua_gettable pops a key from the stack and returns (on the stack) the contents of the table at that key. The table is left where it was in the stack. As in Lua, this function may trigger a metamethod for the "index" event (see 2.8). To get the real value of any table key, without invoking any metamethod, use the raw version: void lua_rawget (lua_State *L, int index); To store a value into a table that resides somewhere in the stack, you push the key and then the value onto the stack, and call void lua_settable (lua_State *L, int index); where index points to the table. lua_settable pops from the stack both the key and the value. The table is left where it was in the stack. As in Lua, this operation may trigger a metamethod for the "settable" or "newindex" events. To set the real value of any table index, without invoking any metamethod, use the raw version: void lua_rawset (lua_State *L, int index); You can traverse a table with the function int lua_next (lua_State *L, int index); where index points to the table to be traversed. The function pops a key from the stack, and pushes a key-value pair from the table (the "next" pair after the given key). If there are no more elements, then lua_next returns 0 (and pushes nothing). Use a nil key to signal the start of a traversal. A typical traversal looks like this: /* table is in the stack at index `t' */ lua_pushnil(L); /* first key */ while (lua_next(L, t) != 0) { /* `key' is at index -2 and `value' at index -1 */ printf("%s - %s\n", lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1))); lua_pop(L, 1); /* removes `value'; keeps `key' for next iteration */ } While traversing a table, do not call lua_tostring directly on a key, unless you know that the key is actually a string. Recall that lua_tostring changes the value at the given index; this confuses the next call to lua_next. Ich vermute mal, das ist Lösung dazu in C. In BlitzMax müsste das dann äquivalent zu den Funktionen sein: Code: [AUSKLAPPEN] Function lua_gettable(lua_state:Byte Ptr,tableIndex:Int) Function lua_settable(lua_state:Byte Ptr,tableIndex:Int) Function lua_rawset(lua_state:Byte Ptr,idx:Int) Function lua_rawget(lua_state:Byte Ptr,idx:Int) Function lua_next(lua_state:Byte Ptr,idx:Int) Werds nacher wenn ich zuhause bin mal austesten.[/code] |
||
SlasHeR |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Also ich bekomms irgendwie nicht hin.
ich verwende direkt den lua core: Code: [AUSKLAPPEN] Import axe.Lua ' Initialize a lua_State Local SE:Byte Ptr = luaL_newstate() lua_register( SE, "MyPrint", LUA_MyPrint ) ' Execute a script with lua_dofile( state:Byte Ptr, path:Byte Ptr ) lua_dofile( SE, "luatest.txt" ) ' First off, get the function from the globals table lua_pushstring( SE , "foo" ) lua_gettable( SE , LUA_GLOBALSINDEX ) ' Push the arguments -- let's say this function takes a string 'lua_pushstring(SE, "Hello, World" ) 'wenn man das auskommentiert hängt das programm. 'wie soll man dann einen table erstellen? crazy..... 'lua_newtable (SE); ' Variables to help you understand lua_call better: Local ArgumentCount:Int = 1 ' You're passing one argument to the function Local ResultCount:Int = 0 ' And you want zero results returned from it ' And call the function lua_call( SE, ArgumentCount, ResultCount ) lua_close(SE) 'api-funktion fuer lua Function LUA_MyPrint( ls:Byte Ptr ) Local args:Int = lua_gettop( ls ) For Local i:Int = 1 To args If lua_isstring( ls, i ) Print String.FromCString( lua_tostring( ls, i ) ) ElseIf lua_isboolean( ls, i ) Print lua_toboolean( ls, i ) ElseIf lua_tonumber( ls, i ) Print lua_tonumber( ls, i ) EndIf Next Return 0 End Function das ist die luatest.txt: Code: [AUSKLAPPEN] function WrapObject() Character = {} Character.name = "Mustermann" Character.vorname = "Hans" foo(Character) end function foo(x) MyPrint("es geht!" .. x) end -- so sollte die funktion eigentlich aussehen --function foo(x) -- MyPrint("Mein name lautet: " .. x.name) -- MyPrint("Mein vorname lautet: " .. x.vorname) --end Die einzigste Notlösung die uns noch eingefallen ist, wäre nicht lua_dofile sondern dostring und einfach die Funktion WrapObjekt() mit Parametern vorher als String zu generieren und vor den ausführbaren Code zu packen. Wenn hier jemand die richtige Lösung zu dem Problem kennt, wäre wir für Hilfe sehr dankbar. |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group