lua-users home
lua-l archive

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


> >> often anyway.  I.e. you want to write t:append(e) instead
> >> of Table.append(t,a) or x:sin() instead of Number.sin(x).
> >>
> 
> whole thing may be the better solution. But even then, think about it 
> first. But please don't force me to do something like this 
> everytime i 
> want a sine of a number
> 
> math.number(55).sin()
> 
> please!
> 
> sin(55)
> 
> is much better, simpler, cleaner.

One of the interesting things about Edgar's Sol approach is that basic
types are automatically "boxed."  That is, they inherit, at no
additional memory or speed hit, a Lua 4.1 work4-like metatable.  For
Sol, those metatables exist as regular tables called Number, String,
etc.  This is an extension of the Lua 4.1 work4 mechanism (which I hope
the Lua team will adopt) which only supports metatables per table and
userdata.

That being said, theoretically, you could write code like:

print(55:sin())
print(55:tostring())

These statements stopped compiling in Lua 4.1 work3, although it worked
in my LuaState C++ distribution that tracked 4.1 Alpha.

Still, being able to do something like:

function Number.tostring(num)
    return "Number: " .. num
end

num = 55
print(num:tostring())

is very, very cool.

It is, in fact, the mechanism I use in LuaState for ANSI and Unicode
strings.

ansiStr = "Hello"
wideStr = L"Hello"

print(ansiStr:lower())
print(wideStr:lower())

In the current Lua 4.1work4 approach, I have no choice but to actually
identify the right function to call:

print(strlower(ansiStr))
print(ustrlower(wideStr))

All credit, of course, goes to Edgar.  This was his idea.  I'd love to
see it implemented in Lua (the basic types support).

Josh