if I call a function foo(t[1])
through the C API, can I in any way see what table and what index is as argument, in this case t
and 1
?
The problem at hand is a function move_card(card, table_slots[0])
where I move a card from one slot on a game area to another one. table_slots
can also be hand
or player_slots
. This can be solved using a metatable, stating the name of the table being accessed. But the index is impossible to solve, or is it? table_slots[0]
can be a card
table, or an overlay
or stack
(arrays of cards), or nil
if it's empty, as could player_slots
. But what I need to know is in fact if it's from a table_slots
or player_slots
.
Could I hack some code analysis? Like, get the line where the function call is made, and then grep the index through a regexp? I could send table_slots[0]
as a string, also, like move_card(card, "table_slot[0]")
. Not as elegant, but still working.
No, once a value reaches a function, be it C or Lua, its origins are lost.
On the other hand, when an error occurs in Lua, the runtime system tries quite a bit to reconstruct the origin of the relevant values, but it does not always succeeds.