Hi AllI want to write a C function that returns a sequence of bytes. This function should be called from Lua. There are two options for the type of return value in Lua - userdata and string. The Lua function that will call this C function wants to access individual bytes of the returned sequence. If string is chosen as the type of return value from C, then the bytes can be accessed as string.sub(ret_str, i, i) where i ranges from 1 to length of ret_str. string.byte(ret_str, i) is also an option. If userdata is chosen as the type of return value from C, then a metatable can be created by the C function before returning the userdata object. The metatable should allow indexed access to individual bytes in the userdata object (Is it possible to write such a metatable?). This would allow ret_val[i] expression to access individual bytes in Lua. How to evaluate (and hence compare) the cost of each of the above approaches?
Asim