Yerbacon/src/headers/transpiler/implementations/Lua.hpp
Username404 4097b1c59a
Lua.hpp: Only output indentation when newLines is set to true
Signed-off-by: Username404 <w.iron.zombie@gmail.com>
2022-05-07 09:37:04 +02:00

35 lines
1.4 KiB
C++

#ifndef LUA_HPP
#define LUA_HPP
using namespace StandardComponents;
struct LuaTarget: Target {
print_functions_pair printFunctions() final { return make_pair("io.write", "print"); }
optional_string uniqueLineSeparator() final { return " "; }
unordered_task_map getTaskMap() final {
return {
make_task(Define,
if (parseComponent.final) output << "local ";
output << parseComponent.name;
if (parseComponent.final) output << " <const>"; // TODO Find an alternative to <const> for lua <5.4
output << " = ";
transpileTree(parseComponent.content);
),
make_task(types::String, stringInterpolation(parseComponent.content, "[[", "]]", "..");),
make_task(Function,
output << "function " << parseComponent.name << '(';
separate_transpileTree(parseComponent.parameters, ", ");
output << ')';
if (not parseComponent.empty()) {
output << separator;
if (newLines) output << indentation;
} else output << ' ';
separate_transpileTree(parseComponent, 1);
if (not parseComponent.empty()) output << separator;
output << "end";
)
};
}
using Target::Target;
};
#endif