lua-users home
lua-l archive

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

On 3/29/14 12:51 PM, Timm S. Mueller wrote:
> The feature list looks awesome, the type system additions, function
> parameter guards, classes and preemptive threads are of major interest
> for me.
[plug] You might like to keep an eye on the czmq bindings:

They're not 100% done yet, but they'll have ØMQ sockets play nicely with
the fiber scheduler and event loop, so that you can effectively do M:N
threading. The thread Pipe implementation which ships with Shine blocks
the entire thread during `get` if there's no pending data and on `put`
if full, so fibers don't get a chance to run. I'm looking at ways around
that, but that's really what ØMQ is good at (you can ask an inproc
socket for its file handle to poll).
> [snip]
> I find it hard to endorse the notation class.func() providing an
> implicit self.
As a quick follow up: methods defined in modules and classes now raise
the familiar "calling 'foo' on bad self (X expected got Y)" if called
with an invalid receiver.

It also works for module mixins:

module M
      print "Hey"

M.greet()         -- OK: modules serve as singletons

class A
   include M

a = A()
a.greet()            -- OK

o = { }
a::greet(o)        -- Error: calling 'greet' on bad self (M expected got

However, this all has a non-zero cost, so I'm undecided as to whether
it'll stay that way or not.

What I might do, as someone else suggested, is allow a compilation
option which disables these assertions. I'll see how well LuaJIT
optimizes this stuff.

For performance critical code you can still create classes and instances
the Lua way (i.e. create your own meta-tables and use `setmetatable` or
the `as` operator).