lua-users home
lua-l archive

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



> On Behalf Of Rici Lake
> On 31-Aug-04, at 4:34 PM, Nick Trout wrote:
> > The only other way I could come up with of doing this without the
> > function name for index argument substitution is to have the
dispatch
> > function return a closure which would then be invoked, calling the
> > function we want. A C or Lua function could be returned. Returning a
> > Lua
> > function would create garbage (eek) and using a C function would
mean 2
> > function calls for every Lua call (inefficient).
> 
> Creating a C closure also creates garbage, unless I'm misunderstanding
> you.

Actually, yes I think you'd have to create a new instance of a closure
unless you hacked into Lua and changed a "reusable" dispatch function. I
suppose you could do something like set a table, which has an entry
which the returned function invoked, so you could set the function in
the table and then call it from there. It's all very messy and slow
though.

I'm liking the sound of this light function idea now. Mmmm it's almost
as though we need metamethods for the compile phase of Lua. I suppose
you're in a grey area between pre-processing and customising the lexer
output processing. This was you could add static linking to objects and
for want of a better description, "const" objects.

Now that would be quite cool, if somehow Lua could inherit some
properties of statically linked languages by customising the compile
phase, but then running as a powerful dynamic language.

Nick