lua-users home
lua-l archive

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


2014-08-25 12:37 GMT+02:00 Coroutines <coroutines@gmail.com>:

> You can "rename" modules at runtime but not userdata internal
> typenames -- you would have to recompile whatever defines those types.

You can rename them.

The string called "tname" that is an argument to some functions in
the auxiliary library is merely a key in the registry associated with
the metatable of the userdata. You have access to the registry via

> R=debug.getregistry()

For example, you can shallowcopy R["FILE*"] to a new table, store
that as R.CLONE, change its __name field to "CLONE", and
debug.setmetatable(io.stdout,R.CLONE).

This is not a particularly useful thing to do. If you print io.type(io.stdout)
you get nil because it is not "FILE*". Calls to the io library do not work,
e.g.

> io.stdout:write"yyy\n"
... calling 'write' on bad self (FILE* expected, got CLONE)

What you can't change is C code that calls those functions from
the auxiliary library. They take const char* arguments. So everything
in the io library still creates and expects tname "FILE*". That's why
writing to stdout failed: "FILE*" is explicitly checked for.

But your spyware module that inspects the innards of someone
else's userdata will not use luaL_checkudata. It will simply use
lua_touserdata, No names, no pack drill.