Created
January 8, 2018 11:48
-
-
Save daurnimator/5a7fa933e96e14333962093322e0ff95 to your computer and use it in GitHub Desktop.
Fengari table=>Object helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local js = require "js" | |
-- Helper to copy lua table to a new JavaScript Object | |
-- e.g. Object{mykey="myvalue"} | |
local function Object(t) | |
local o = js.new(js.global.Object) | |
for k, v in pairs(t) do | |
assert(type(k) == "string" or js.typeof(k) == "symbol", "JavaScript only has string and symbol keys") | |
o[k] = v | |
end | |
return o | |
end | |
return { | |
Object = Object; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes. See the fengari-interop source for how you might do so.