feat(generator): improve `indent` implementation

This commit is contained in:
Aire-One 2022-10-23 21:09:22 +02:00
parent 89f66119ee
commit b1c3d80604
1 changed files with 3 additions and 6 deletions

View File

@ -1,17 +1,14 @@
local Function_Info = require "entity.Function_Info" local Function_Info = require "entity.Function_Info"
local List = require "pl.List" local List = require "pl.List"
local utils = require "utils" local stringx = require "pl.stringx"
local template = require "pl.template" local template = require "pl.template"
local utils = require "utils"
local snippets = {} local snippets = {}
function snippets.indent(str: string, level: number): string function snippets.indent(str: string, level: number): string
level = level or 1 level = level or 1
local ret = "" return stringx.rstrip(stringx.indent(str, level, string.rep(" ", 3)))
for line in str:gmatch("[^\n]+") do
ret = ret .. string.rep(" ", level * 3) .. line .. "\n"
end
return ret
end end
function snippets.render_typed_variable(name: string, types: List<string>): string function snippets.render_typed_variable(name: string, types: List<string>): string