[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua is not skin deep
- From: "steve donovan" <steve.j.donovan@...>
- Date: Tue, 6 Nov 2007 15:17:46 +0200
I'm coming to agree with Fabien that any meta-extension should be used
to add _new_ things to Lua, not confuse the issue with curly braces ;)
The proposal of the day: type annotations for function 'prototypes':
Consider this hypothetical syntax:
function F(String s, Number t)
The actual code that the compiler sees is this:
where _assert_type() is:
local t = type(value)
if t ~= typestr then
local msg = ("Argument '%s' expects a type of '%s', got
This is doubly useful: first, you can decorate your function
prototypes with useful type annotations. Second, you can dynamically
enforce that contract.
This all worked fine with the latest version of the token-filter macro
library; I'll post the code and some examples somewhere appropriate.
PS. On the subject of whether Lua is up to the processing task, I
created a test file with 10,000 function definitions like this.
Parsing with the type-annotations macros took little over a second.
This seems to reflect the sheer numbers of lexical replacements
involved; a similar file with no type annotations was parsed in about