(feel free to move this topic if isn't in the correct category)
ok. i start to play with plugins...
this is the lua code...
with some var, a table...
call a C function "tntengine.alphamorph(color, ferro, ciccio)" this do some on the parametres passed and modify directly some filed of the table... then release 3 values...
this example works fine but...
require "tntparticlesengine"
color = 1000
ferro = 2000
ciccio = {Nome = "ciao",
xPos = 10,
yPos = 20,
Color = 1.212,
linee = {},
spazi = 23
}
a,b,c =tntengine.alphamorph(color, ferro, ciccio)
print("-----")
print(a)
print(b)
print(c)
print(ciccio.xPos)
print(ciccio.yPos)
print("-----") |
#include "lua.h"
#include "lauxlib.h"
#include "gideros.h"
static int alpha_morph(lua_State *L) {
double color = lua_tonumber(L, -3);
double ferro = lua_tonumber(L, -2);
lua_pushstring(L, "Color");
lua_gettable(L, -2);
double spazi = lua_tonumber(L, -1);
lua_pop(L, 1);
color++;
ferro--;
lua_pushstring(L, "xPos");
lua_pushnumber(L, 256);
lua_settable(L, -3);
lua_pushstring(L, "yPos");
lua_pushnumber(L, 156);
lua_settable(L, -3);
lua_pushnumber(L, color);
lua_pushnumber(L, ferro);
lua_pushnumber(L, spazi);
return 3;
}
static const struct luaL_Reg tntEngineFuncs[] = {
{ "alphamorph", alpha_morph },
{ NULL, NULL }
};
LUALIB_API int luaopen_tntparticlesengine(lua_State *L) {
luaL_register(L, "tntengine", tntEngineFuncs);
return 1;
} |
stack index of parametres passed in the func are:
for 1^st "color" is -3 for "ferro" is -2
but why for the table "ciccio" is -2 and not -1 ?
i miss something... how work exactly the stack with simple parametres and tables ?
i pass an object how can access to it ?
there is a better way to change directly a value in the table than this :
lua_pushstring(L, "xPos");
lua_pushnumber(L, 256);
lua_settable(L, -3); |
what means really " lua_settable(L, -3);"
thanks.
and sorry for my continuous questions ...
but the possibility of using the plugin really interests me ...
...when I have more experience I hope to give something back to communities...
Gianluca.
Comments
When you first go in, the table ciccio is presumably at -1, then you push the string "Color", so "Color is at -1 and ciccio is at -2 now.
Have you read the Ultimate Guide, Chapter 8?
http://giderosmobile.com/DevCenter/index.php?title=Ultimate_Guide_to_Gideros_Studio
8.2 has a table indicating what 1,2,3 and -1,-2,-3 are.
It is a very complex subject, and I am quite happy to acknowledge that I may not have presented it completely the best. However, it will be very useful to test it on an actual unsuspecting user , so that we can make the Guide the best.
The code in the guide is a bit fragmented, but you can download a working plugin with the Gideros project, and this has a few examples of various things you can do.
http://www.giderosmobile.com/forum/discussion/433/sample-iphone-plugin
I did write it for iOS though. Perhaps I should put in my signature that I know nothing about Android (insert dunce emoticon here )
Likes: atilim, GregBUG
I read the manual but in a hurry and at night... better to make things very quietly ...
you have presented this subject very clearly!
but it's my desire to learn that I care... and the fact that I do not understand English well ... (my mother language is Italian) and use google translator!
PS: your example (and that one posted by MikeHart) is very good but i don't understand well Objective C.
BTW, now the "stack" is clear... i need to make some practice with it! now!...
ps: I'll probably still have some "stupid" questions...
I warned you!
thanks.
ciao!
Gianluca.
www.tntengine.com
To access the parameters that are passed to a C function, it's better to use positive indices. I mean instead of
http://pgl.yoyo.org/luai/i/lua_tonumber
http://pgl.yoyo.org/luai/i/luaL_checknumber
Also using lua_setfield and lua_getfield is easier for changing a field of a table. I mean, instead of
http://pgl.yoyo.org/luai/i/lua_setfield
http://pgl.yoyo.org/luai/i/lua_settable
best,
http://pgl.yoyo.org/luai/i/lua_rawgeti
http://pgl.yoyo.org/luai/i/lua_rawseti
(But then I am backwards about many things.)
Your other points are good ones. I always forget to use the checknumber instead of tonumber.
thanks for the tips.!
Likes: atilim
www.tntengine.com
Likes: atilim