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

Updated the load() function in the parser to return the G object that it creates. #1

Closed deltaflux closed 12 years ago

deltaflux commented 12 years ago

While trying to use lua+parser.js I noticed that the load() function created by lua_load() would never actually return the G variable that it creates, meaning that I couldn't access the data. With this change my usage is

var luaLoaderFunction = lua_load(luaScript); var luaObject = luaLoaderFunction();

Let me know if I've misunderstood how to use lua_load() and this fix is incorrect. Thanks.

mherkender commented 12 years ago

Thanks for pointing this out. This is definitely a bug, a regression that occurred a while back.

The fix I committed is a little different then yours though, lua_load itself needs to add the "return G;" since the code in lua.jison does not include the wrapper around generated code. If you look at lua2js_end you'll see it includes the "return G" itself.