2

I would like to know how I can pass a parameter table from a lua function to a C function. I found some example but they didn't explain how we can get back our table in our C function. If we pass a number from lua to C, we use luaL_checkint it's simple. But we can not doing the same thing with table.

For example in my lua function I call a C function like that :

local a, b= library.executeDiagRequestOnChannel(test,test2) 

where library is my new library for my embedded system functions, test and test 2 are two tables, and executeDiagRequestOnChannel is a function of my library.

In my C file, I have the function :

static long executeDiagRequestOnChannel(lua State *L){} 

and I want in this fonction do operation on my tables test and test2 and sent back after to lua function the result.

8
  • You use the table inspection functions in the api. You don't pull the table off the stack into a C variable. Commented Aug 21, 2014 at 15:55
  • @EtanReisner I need to get back the table from lua function parameter in a C function, because I want to do some operation with this table. For example in my lua function I call a C function like that : local a, b= library.executeDiagRequestOnChannel(test,test2) where library is my new library for my embedded system functions, test and test 2 are two tables, and executeDiagRequestOnChannel is a function of my library. Commented Aug 22, 2014 at 7:22
  • @EtanReisner ... In my C file, I have the function : static long executeDiagRequestOnChannel(lua State *L){} and I want in this fonction do operation on my table and sent back after to lua function the result. Commented Aug 22, 2014 at 7:31
  • 2
    Yes, but that's not the point. The point is that a lua table isn't a C primitive so you can't get a C variable with the table in it. So what you do instead is operate on the table (which lives on the lua stack) by using the lua table manipulation functions in the API. Functions like lua_gettable, lua_getfield, etc. Commented Aug 22, 2014 at 12:01
  • 1
    Yes, that's the idea. The checktype function is checking the item at that stack index. lua_gettable is operating on the table at the given index and using the value from the top of the stack as the key, etc. Commented Aug 22, 2014 at 12:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.