3 ms·
Factor, Racket, and Lua all have ffi's that are very easy to use. I've never quite liked Lua's metaprogramming, though (macros are very useful when you're writi
by copper 15y ago
Factor, Racket, and Lua all have ffi's that are very easy to use. I've never quite liked Lua's metaprogramming, though (macros are very useful when you're writing bindings.) and my least favourite Lua quirk would be the lack of integer types - both other languages have fairly sane (and performant!) numeric towers.
That said, I'd give a higher priority for the language in my browser to be safe: some kind of correctness guarantee would be nice. Or even, while we're at it, some kind of way to analyze the script and say "this script GETS from urls x,y, and posts data d to z"
- dkersten 15y agoStandard Lua may not have integer types, but as far as I know, LuaJIT does actually support integer types under the hood. At the very least, you can force it by declaring an integer using the FFI, eg: local ffi = require("ffi") int = ffi.new("int") int = 10 print(int) I also don't find the lack of macros in Lua as limiting as I do in other languages. For example, if I wanted to create an EDSL in Lua, I would have it parse a string at startup. For example, imagine a state machine DSL: fsm = my_dsl[[ start: foo stop: quux foo -> bar foo -> baz bar -> foo baz -> quux ]]{ foo = function() code for foo here end, bar = function() code for bar here end, baz = function() code for baz here end, quux = function() code for quux here end } fsm.run() As a real-world example, here is some Lua code I'm using in a hobby game project: DEFINE(Traits.Position)[[ float x; float y; float z; ]] DEFINE(Traits.Movement)[[ float x; float y; float z; ]] DEFINE(Behaviors.do_movement){ input={Traits.Position, Traits.Movement}, output=Traits.Position, frequency=0.01, -- Update entities position fn = function (pos, mov) local delta = dark.timedelta new_pos = Traits.Position.new() new_pos.x = pos.x + (mov.x * delta) new_pos.y = pos.y + (mov.y * delta) new_pos.z = pos.z + (mov.z * delta) return new_pos end} -- Create a sample entity local entity = Entities.new() entity.add(Traits.Position, {1.0, 0.0, 0.0}) entity.add(Traits.Movement, {0.0, -1.0, 0.0}) "That said, I'd give a higher priority for the language in my browser to be safe: some kind of correctness guarantee would be nice. Or even, while we're at it, some kind of way to analyze the script and say "this script GETS from urls x,y, and posts data d to z"" I definitely agree with the above.