-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't compile and run React.JS #1
Comments
Hello @daurnimator, |
No problem, I think CASTL is an interesting idea, even if I don't have an application for it yet.
Thanks!
Ah ha, yeah, it looks for
Thanks for that hint. With that small modification, React seems to at least load :D I'll have a closer look into seeing if it actually does what it should soon. |
Thanks, looks like you fixed that in 7b3ad4f
I'm now just trying to run the most minimal of React code: local React = require "react"
local c = React.DOM:h1({}, "Hello world!")
print(React:renderComponentToString(c)) But getting an error:
It appears I need to wrap my table; which is reasonable: local React = require "react"
local cr = require("castl.runtime")
local Object = cr._obj
local c = React.DOM:h1(Object{}, "Hello world!")
print(React:renderComponentToString(c)) This runs, but prints out the wrong thing..... a random html element. e.g. This indicates that something is wrong elsewhere.... |
I had a hardtime figuring out what was going on (and fixed 2 others little things in passing) and I found that the core problem come from lua5.2:
If you execute this snippet with Lua5.2 you get something like:
So if you store these local functions in an array for example they'll all point to the same address, which is not the expected behavior in JS... By the way if you execute this code with Lua5.1 or LuaJIT it's ok:
Did you ever heard about this problem and any workaround? (I believe Tessel modified their lua VM to fix it) |
This usually isn't a problem but a feature. Identical functions compare equal :p You could get around it by having non-identical functions (e.g. if they have a different upvalue) for i=0,5 do
local a = function() local _ = i end;
print(a);
end
Or by wrapping them (which you sort of should be doing to get JS semantics around functions anyway): local Func_mt = {
__call = function(t,this,...)
return t.raw(this,...)
end;
}
local function JSFunc(raw)
return setmetatable({raw=raw}, Func_mt)
end for i=0,5 do
local a = JSFunc(function() end);
print(a);
end
Of course, you can put a nice |
I had another attempt at this today with a newer release of react: local React = require "react"
local cr = require("castl.runtime")
local ReactDOMServer = React.__SECRET_DOM_SERVER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED -- I don't know how to access things `define`d with castl.
local Object = cr._obj
local c = React.DOM:h1(Object{foo="bar"}, "Hello world!")
local s = ReactDOMServer:renderToString(c)
print(s) it doesn't return anything. I tried to track it down but ran out of time. |
I figured out the root cause: it's a pretty deep problem with regular expression including some utf8 characters... I'll try to find a fix for that. Still I don't understand why the error thrown don't propagate and is not displayed explicitly, took me hours to understand. |
@zeen thought it would be cool to compile React.JS into Lua.
The JS source file: http://fb.me/react-0.11.1.js
The first error is
Which comes from https://github.com/facebook/react/blob/8cb2812cff6a6cb54bb673254f1170281ce0790a/src/browser/ui/ReactDefaultInjection.js#L117 I just set the conditional to false so I could continue; but there's something weird going on there.
The next error I get is
Which is in the module definition bit at the start.
The text was updated successfully, but these errors were encountered: