diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua index a7c4b9d..7fd9551 100644 --- a/nomsu_compiler.lua +++ b/nomsu_compiler.lua @@ -236,15 +236,16 @@ local compile = setmetatable({ end local lua = LuaCode:from(tree.source) lua:add((stub):as_lua_id(), "(") - for i, arg in ipairs(tree:get_args()) do + for argnum, arg in ipairs(tree:get_args()) do local arg_lua = compile(arg) if arg.type == "Block" then arg_lua = LuaCode:from(arg.source, "(function()\n ", arg_lua, "\nend)()") end - if i > 1 then - lua:add(",") + if lua:trailing_line_len() + #arg_lua:text() > MAX_LINE then + lua:add(argnum > 1 and ",\n " or "\n ") + elseif argnum > 1 then + lua:add(", ") end - lua:add(lua:trailing_line_len() + #arg_lua:text() > MAX_LINE and "\n " or " ") lua:add(arg_lua) end lua:add(")") diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon index 720fe03..bffec92 100644 --- a/nomsu_compiler.moon +++ b/nomsu_compiler.moon @@ -174,12 +174,14 @@ compile = setmetatable({ lua = LuaCode\from(tree.source) lua\add((stub)\as_lua_id!,"(") - for i, arg in ipairs tree\get_args! + for argnum, arg in ipairs tree\get_args! arg_lua = compile(arg) if arg.type == "Block" arg_lua = LuaCode\from(arg.source, "(function()\n ", arg_lua, "\nend)()") - lua\add "," if i > 1 - lua\add(lua\trailing_line_len! + #arg_lua\text! > MAX_LINE and "\n " or " ") + if lua\trailing_line_len! + #arg_lua\text! > MAX_LINE + lua\add(argnum > 1 and ",\n " or "\n ") + elseif argnum > 1 + lua\add ", " lua\add arg_lua lua\add ")" return lua