mherkender / lua.js

An ECMAscript framework to compile and run Lua code, allowing Lua to run in a browser or in Flash
http://blog.brokenfunction.com/
600 stars 73 forks source link

tostring(), functions as keys #18

Closed ggcrunchy closed 11 years ago

ggcrunchy commented 11 years ago

Hi.

I did a few things, trying to get some of my libraries to cooperate with the Love2D WebPlayer.

I depend in some places on functions as keys. Since that wasn't supported, I first used tostring() as a hack, appending an ID to "function" (and "table"). I'm VERY green on Javascript, so I'm not all that certain about what I did, but there it is.

Investigating, I saw that the only thing really holding back the functions was another array like "objs". Since you didn't add one, I decided to only load one on the fly... looking at it now, I guess I didn't need to put it in the bool object, but I figured we knew what keys that could hold and thus wouldn't stomp on anything. (As an aside, doing this, I did flush out that "bools" was used by accident in the pairs() function.) So far, it looks like copying the "objs" logic in rawget() and rawset() was enough...

Last but not least (and I can post this as an issue if you'd prefer), this construct fails:

local ipairs = ipairs

since it resolves to something like "var _ipairs_63 = _ipairs_63;" and ends up null. It's easy to avoid (by just excising those parts from the files), but pretty annoying when one can't just drop in code.

Thanks!

mherkender commented 11 years ago

The problem with the method you're using is that a table of every function is maintained indefinitely, allowing none to be cleaned up. I'm not against the technique though, perhaps it could be modified to tie the kFUNCS variable to the function itself. I think I'll take a look another look at this problem.

I'll check out "local ipairs = ipairs", that's a bug.

mherkender commented 11 years ago

Okay, I believe the variable issue has been fixed, as well as the pair() issue you mentioned in another post.

I don't have a good way to do function key lookups, at least not yet, but ideas are still welcome.

ggcrunchy commented 11 years ago

Great, thanks! I'll report any problems if they come along.

On lookups, I probably need to read up on how reachability works, before offering any ideas. In the meantime, I'll see if I get by with my kludge. :smile: