[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: How to create a C func that returns a lua table
- From: Anders Eriksson <Anders.Eriksson@...>
- Date: Thu, 18 Aug 2005 15:28:03 +0200
As a newbee, I can't figure this one out!
What have I missed ? I want this C func return
a lua table.
-- C code
int l_GetPosTable(lua_State* l)
{
printf("Create table\n");
lua_newtable(l);
// Position
setTableField(l,"px",1.0);
setTableField(l,"py",233.33);
setTableField(l,"pz",3.0);
// X orientation vector
setTableField(l,"xx",1.0);
setTableField(l,"xy",0.0);
setTableField(l,"xz",0.0);
// Y orientation vector
setTableField(l,"yx",0.0);
setTableField(l,"yy",1.0);
setTableField(l,"yz",0.0);
// Z orientation vector
setTableField(l,"zx",0.0);
setTableField(l,"zy",0.0);
setTableField(l,"zz",1.0);
return 1;
}
-- end C code
And in my lua script I do like this!
local tpos = GetPosTable()
print(tpos) -- says it's a table :)
print(tpos[1]) -- says nil :(
/Anders E.