lua-users home
lua-l archive

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


2015-08-20 19:27 GMT+02:00 Tim Hill <drtimhill@gmail.com>:

> Since userdata is opaque to Lua, any operation on that userdata
> must involve a call to a C function with the userdata as an argument.
> Once you do this, all the issues discussed here go away; it’s easy
> to provide the extra metadata about a userdata using any number
> of indirection/tagging techniques at the C level, including lifetime
> management if you want to (for example) refcount etc.

On Unix systems (I can't speak for others) it is quite common
to have a single executable that is symlinked to several names.
They are called multi-call binaries. One of the best known is
busybox. Exactly what it does when called depends on the name
that you use to call it. One program, many names.

The original idea is similiar, with userdata instead of executable
and TValue instead of name. One userdata, many meanings of
__index and __newindex.

Here but for the code of module "matrix" (which is in Lua but
uses calls to settypetag) is an example, similar to the OP's
except that A is a table.

matrix = require "matrix"
A = matrix(10,10) -- filled with 100 zeros
B=A:row(3)
C=A:column(5)
print(A,B,C) -- Three copies of "table: 0x2293df0".
A[25] = 1000
print (B[5],C[3]) -- 1000 1000