I've been experimenting with exactly this sort of thing here:
https://github.com/richardhundt/lupa/tree/method-accessors
It's essentially a transpiler which compiles an OO curly brackety language to Lua source code. It supports guard expressions which are evaluated at run-time. I had this extended at some point to include cdata types.
The tests show examples of the language:
https://github.com/richardhundt/lupa/blob/method-accessors/test/class.ku
run with:
./bin/kula <file>
I decided to do a complete rewrite though in this branch:
https://github.com/richardhundt/lupa/tree/setfenv-for-namespaces
and I haven't got guards in yet since I've decided to build a bytecode compiler for LuaJIT2 first:
https://github.com/richardhundt/luajit2-codegen
It's all highly experimental and a bit messy, the branches diverge hugely, but right now I prefer to keep it that way because I haven't settled on the syntax and semantics yet.
Hopefully, though, you can get an idea of what can be done and how it performs. You need a fresh version of LPeg to make it work.
Cheers,
Richard
This looks extremely interesting. The syntax seems pretty neat compared to lua, and in fact there seem to be ideas there that haven't been explored in many languages yet. I might go as far as using this language, if the inheritance mechanisms are powerful enough.
Also, as suggested, I have performed a benchmark on the typecheck thing, and the results are.. surprising.
function A(n : Number, i : Number) {
return n + i
}
n = 0
for i=1,5_000_000_000 {
n=A(n,5)
}
print(n)