From 2360ada21fac914a4bc5eeec752966cb3f3bba71 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 14 Dec 2018 19:25:59 -0800 Subject: Codegen tweak --- nomsu_compiler.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'nomsu_compiler.lua') 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(")") -- cgit v1.2.3