[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] vstruct - 1.0 beta 2
- From: Ben Kelly <ranavin@...>
- Date: Fri, 25 Jul 2008 10:03:18 -0400
Christof Schardt wrote:
> In read.lua:
> u = u * 2^8 + s:sub(i,i):byte()
> could be changed to
> u = u * 2^8 + s:byte(i)
Good catch! I keep forgetting you can do that with byte().
> BTW: "2^8", will this this optimized by the interpreter, or
> should you rather write 256?
It'll be optimized. You can verify this with luac, a practice I highly
encourage:
$ echo 'return 2^8' | luac -l -
main <stdin:0,0> (3 instructions, 12 bytes at 0x8982b30)
0+ params, 2 slots, 0 upvalues, 0 locals, 1 constant, 0 functions
1 [1] LOADK 0 -1 ; 256
2 [1] RETURN 0 2
3 [1] RETURN 0 1
> Generally: nice, luaish peace of code.
>
> The tricky module-mechanism is not easy to
> understand. I mean things like this
>
> local name = (...):gsub('%.[^%.]+$', '')
> local read = require (name..".read")
>
> and similar lines.
I'm not actually entirely happy with that; it feels ugly and slightly
hackish. I have yet to come up with a better way, though.
> Wouldn't it be worthwhile to explain this idiom and
> put it as a "Lua-Mini-Gem" to the Wiki?
> (while we are waiting for the Lua Gemas ;-)
There's a thought. NameIndependentModules, perhaps?
Ben Kelly