[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ClojureScript/Lua
- From: David Manura <dm.lua@...>
- Date: Tue, 14 Aug 2012 22:30:12 -0400
On Thu, Aug 9, 2012 at 4:26 AM, Eike Decker <zet23t@googlemail.com> wrote:
> Quoting from the site
>> "The first thing i had to overcome in porting the Javascript backend
>> to Lua, is that in Lua, not everything is an object. "
>[...]
> -- setting the metatable of one function affects all functions...
> debug.setmetatable(function()end,{__index = function (f,k) return "foo" end})
Achieving the desired "store all kinds of information on the function
itself, which you can use later. The clojurescript compiler uses that
extensively, most notably for variable arity function dispatch, and
for functions with rest arguments" might also be done with some global
weak tables keyed by a function object:
local cljs__lang__arity__1 = setmetatable({}, {__mode='k'})
...
cljs__lang__arity__1[a] = function (b) return b end
I don't know if they considered that, but it avoids both the
functables and debug.setmetatable.