]> git.lizzy.rs Git - protogen.git/commitdiff
Add sub functions
authorElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 15 Apr 2022 17:10:46 +0000 (19:10 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 15 Apr 2022 17:10:46 +0000 (19:10 +0200)
protogen.lua

index 130859de31eae28eccafc12be6aa1545ec21b4a6..9b98280cb175c1d70ee6a6d06202de6c3b21bc11 100755 (executable)
@@ -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")