lua-users home
lua-l archive

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


>From lua-l@tecgraf.puc-rio.br  Mon Jan 31 08:35:03 2000
>From: "Maciej Maczynski" <macmac@xdsnet.de>
>
>I have C-function registered with lua_register.
>How can I protect them from being re-defined in Lua code?
>I've tried the piece of code from FAQ, but it seems to be working only with
>native Lua functions.

Section 3.3 of the FAQ contains

settagmethod(tag(protect),"setglobal",protect)

This protects *all* Lua functions, because we are using "tag(protect)", and
"protect" is a Lua function.
To protect a C function named "f", do

settagmethod(tag(f),"setglobal",protect)

but note that this protects *all* C functions because all C functions have the
same tag.

If Lua allowed tags to be set for functions, then you could proctect only f
by simply setting a newtag for f and using this tag in settagmethod.
However, you can use the more elaborated scheme described in FAQ 3.3.
--lhf