lua-users home
lua-l archive

Re: global environment special case

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


> By making this change the Lua language and documentation would be
> simplified, and I believe the complexity of implementing extensions would
be
> reduced.
Recently I did a test to determine how the "global environment as a table"
change would affect an extension. I re-implemented my function overloading
extension to operate on tables instead of the global environment, and added
an init function that applies it to any table given its tag number:
 function overload_init( tagnum )
 settagmethod( tagnum, "settable", tm_settable )
 settagmethod( FuncRecTag, "function", tm_function )
 end
Given the change I proposed, the extension could now be used with both the
global environment and tables:
 overload_init( tag(globaltable()) )
 overload_init( tag(mytable) )
However there is an issue here that those experienced with Lua extensions
will quickly recognize. The "settable" tagmethod cannot be set for tables
with a default tag. So this raises some questions:
 What tag will the global table have by default?
 Can the global table's tag be changed?
I think this is getting at the heart of the difference between the
interfaces Lua presents to tables and the global environment. In addition,
a related question might be this:
 Can the restrictions on tagmethods be loosened without significantly
affecting performance?
-John

AltStyle によって変換されたページ (->オリジナル) /