lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

It's a little hard to explain. I use lua table to describe a C struct. I write a parser to parse the table into C struct. 
And I write a tool that use to do this:
       Covert lua table to C struct   ->     C struct to packet   ->   send to server   - >   get respone packet  ->   packet to C struct
->   get some field of the respone C struct to fill in (or do something) a new lua table ->  Covert lua table to C struct -> ....

Then functions like "GetValue" is to do the sixth step

Maybe it's still not clear. 

At 2012-07-16 18:12:46,"Patrick Rapin" <> wro
>> GetValue's C code:
>> static int GetValue_Factory(lua_State *L)
>> {
>>   lua_pushcclosure(L, GetValue, 2);
>>   return 1;
>> }
>> static int GetValue(lua_State *L)
>> {
>>   lua_pushvalue(L, lua_upvalueindex(1));
>>   lua_gettable(L, lua_upvalueindex(2));
>>   return 1;
>> }
>I am a bit puzzled with that piece of code.
>The GetValue function takes no argument from Lua stack, but takes two
>constant arguments from its upvalues.
>When you wrote "GetValue( 0, table )" or "GetValue( '0', table )", did
>you actually call the GetValue_Factory C function ?
>If yes, you have to call the resulting function value: "GetValue ( 0,
>table ) ( ) ".
>If no, the arguments would be just ignored.
>Could you explain a little bit more the situation ?