From: Elias Fleckenstein Date: Fri, 15 Apr 2022 17:10:46 +0000 (+0200) Subject: Add sub functions X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=7e7800f0fa64ed9b1c4d5ee42103923ebe195ce5;p=protogen.git Add sub functions --- diff --git a/protogen.lua b/protogen.lua index 130859d..9b98280 100755 --- a/protogen.lua +++ b/protogen.lua @@ -132,12 +132,13 @@ local function emit_vector(type, l) existing_types[box] = true has_deallocator[box] = false - local typedef, equals, add, clamp, cmp, scale, mix, write, read, send, recv = - "", "", "", "", "", "", "", "", "", "", "" + local typedef, equals, add, sub, clamp, cmp, scale, mix, write, read, send, recv = + "", "", "", "", "", "", "", "", "", "", "", "" typedef = typedef .. "\t" .. type .. " " equals = equals .. "\treturn " add = add .. "\treturn (" .. name .. ") {" + sub = sub .. "\treturn (" .. name .. ") {" clamp = clamp .. "\treturn (" .. name .. ") {" cmp = cmp .. "\tint i;\n" scale = scale .. "\treturn (" .. name .. ") {" @@ -169,6 +170,14 @@ local function emit_vector(type, l) or ", " ) + sub = sub + .. "a." .. c .. " - " + .. "b." .. c .. + (last + and "};\n" + or ", " + ) + clamp = clamp .. type .. "_clamp(" .. "val." .. c .. ", " @@ -219,6 +228,7 @@ local function emit_vector(type, l) emit(export_prefix .. "bool " .. name .. "_equals(" .. name .. " a, " .. name .. " b)", "{\n" .. equals .. "}\n\n") emit(export_prefix .. name .. " " .. name .. "_add(" .. name .. " a, " .. name .. " b)", "{\n" .. add .. "}\n\n") + emit(export_prefix .. name .. " " .. name .. "_sub(" .. name .. " a, " .. name .. " b)", "{\n" .. add .. "}\n\n") emit(export_prefix .. name .. " " .. name .. "_clamp(" .. name .. " val, " .. name .. " min, " .. name .. " max)", "{\n" .. clamp .. "}\n\n") emit(export_prefix .. "int " .. name .. "_cmp(const void *a, const void *b)", "{\n" .. cmp .. "\treturn 0;\n}\n\n") emit(export_prefix .. name .. " " .. name .. "_scale(" .. name .. " v, " .. type .. " s)", "{\n" .. scale .. "}\n\n")