lua-users home
lua-l archive

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


In my experience with binary constants they are only used to set the value of a named constant. Then in the code the named constant is used. 

Considering the simple workaround mentioned by Steve, the costs (memory and speed) of adding the power patch to the lua core should be really small/negligible to justify inclusion. To not help out those who use it at the cost of those that don't. 

Ps1: I do like the notation
Ps2: nitpick;  the memoize element in the workaround doesn't really help as typically every constant is parsed only once

Thijs



-------- Original message --------
From: steve donovan <steve.j.donovan@gmail.com>
Date:
To: Lua mailing list <lua-l@lists.lua.org>
Subject: Re: [ANN] Lua 5.3.0 (work1) now available



On Sun, Jul 14, 2013 at 4:55 PM, John Hind <john.hind@zen.co.uk> wrote:
local x = 0b1001_0001 - support of underscores here is particularly useful
to break long bitmaps into fields - they're just for documentation and get
ignored).

This is cool; there are two ways to get this with existing Lua. One, define a memoized conversion function 'b' and then you can write b'1001_0001' to represent binary patterns. Two, hook into current environment with __newindex and convert globals looking like b1001_0001. (Implementation left as exercise)