Skip to content

how is babby formed #31

@natevw

Description

@natevw

Would be nice at some point to have an official overview of how this works. I did find https://www.npmjs.org/package/lua-colony#readme to be helpful although maybe a bit has changed since then.

AFAICT, compilation is more of a syntax conversion — e.g. JavaScript uses braces, Lua uses "end"; plus a few tricks/conventions to pull off "various things" (?). But once you've got the code roughed into shape, the rest of the work is done by "monkeypatched" Lua builtins (primitive strings/numbers/etc and object/array-ish tables) with methods and operators to the point where they ± match JavaScript's behavior.

JavaScript code like ""+{abc:42,fn:function () {}}.abc more or less becomes:

((""))+(_obj({
  ["abc"]=(42),
  ["fn"]=(function (this)
--[[28]] if true then return (false); end
end)
}).abc)

… and the + operator ends up doing JavaScript-ish string concatentation due to a custom .__add metatable method on the Lua side (code in runtime's colony-init.lua). The .abc property lookup similarly goes through js_proto_get via a custom .__index method^Wmetamethod.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions