lua-users home
lua-l archive

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


Hi, section 3.5 of the Lua reference manual states:

"There is no direct way to convert the pointer [obtained by lua_topointer] back to its original value."

I'm just curious, is there an indirect way?

If there are good reasons against pointer casts in general, can we at least enable it for debugging purposes?

The problem domain would be table expansion in a remote debugger. If a table contains a key value pair where the key is a memory address (i.e. a userdata), and the value is a table (i.e. a table associated with the userdata), trying to retrieve that table remotely is tricky business. To be 100% correct, the debugger would have to know the following info when the user chooses to expand a table:
- string representation of the key (a pointer)
- type of the key
- full name of the parent table

And then send that information back to the target (i.e. the game) to retrieve the table. On the target side, one would traverse all entries under the parent table, and when there is a match for both the key and the type of the key, the table has been found.

Contrast this with the simplicity of expanding a table associated with a non-pointer key. The table to be retrieved is simply parentTable[ keyName ]  (for number and boolean keys) or parentTable[  [[ keyName ]] ] (for string keys). 

Tai