   Quick Help
  Why does this return a function value when its called.  It should return the table.static int Object(lua_State* L) {const char *val = lua_tostring(L, -1);lua_newtable(L);    lua_pushvalue(L, -1);    lua_setmetatable(L, -2);    lua_pushliteral(L, "__index");    lua_pushcfunction(L, __index);    lua_pushliteral(L, "__tostring");    lua_pushcfunction(L, __tostring);Triangle Test;Test.Pointer = (int*)lua_topointer(L, -5);AddObject(Test);    lua_settable(L, -5);return 1;}
  Anyone?   ;Quote:Original post by Matthew ShockleyWhy does this return a function value when its called.  It should return the table.*** Source Snippet Removed ***It looks like you are only calling settable once at the end, you should call it twice (as it looks like you are putting two things in your table. This returns a function because the thing on top is a function (because you didn't take it off and put in the table). The function you are returning is __index (__tostring got settabled).Could you comment it a bit so we can see what your doing? Your style is much diff from mine, and Lua API is not very self-documenting.Lets see if I understand correctly:Takes one string argument (I would use positive indicies for args, in case they pass one extra or something), which is unused right now.You create a table, make it it's own metatable, and then put an __index and __tostring cfunction in it (you should use settable immediately after pushing a name/val pair, so you have minimum stuff to think about on the stack).Then you are doing something wierd with a traingle (comments please?). Keep in mind that topointer is NOT reversible, and not garbage collected.The settable should go after the pushes, as I mentioned above.Do I comprehend?   ;  Oh, I only thought you used settable once.  Thanks.   ;  I meant to mention this earlier, C identifiers that begin with double underscores are reserved for the compiler implementation and should not be used. In other words, don't name your C functions __index or __tostring.See this for more info.   