diff options
author | sanine <sanine.not@pm.me> | 2023-02-19 19:03:51 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-02-19 19:03:51 -0600 |
commit | fb0eb6abac31ab1945a5b32e68824c9f9420d71f (patch) | |
tree | b414bb9f93af85755df553d003ed88afc24cef50 /util/generate-binding.lua | |
parent | bc4af3b47260ee0f79343303b135d1ea32cde4d4 (diff) |
refactor: bind (nearly) all nvg functions
Diffstat (limited to 'util/generate-binding.lua')
-rw-r--r-- | util/generate-binding.lua | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/util/generate-binding.lua b/util/generate-binding.lua new file mode 100644 index 0000000..1c5359f --- /dev/null +++ b/util/generate-binding.lua @@ -0,0 +1,62 @@ +local b = {} +setmetatable(b, {__index=G}) +setfenv(1, b) + + +--===== enums =====-- +local Enum = {} +-- create a single enum element +function Enum.new(name, id) + local self = { + name = string.upper(name), + id = id, + } + setmetatable(self, Enum) + return self +end +-- create multiple enums +function Enum.new_multi(tbl) + local enums = {} + for id, name in ipairs(tbl) do + table.insert(enums, Enum.new(name, id)) + end + return enums +end +-- make enums read-only +function Enum.__newindex(self) + error("Attempted to set index on Enum") +end +-- make enums print nicely +function Enum.__tostring(self) + return self.name +end +-- allow comparinge enums +function Enum.__eq(self, other) + return self.id == other.id +end + + +local function check_match(string, pattern, rule) + local match = string.match(string, '^' .. pattern) + if match then + return match, rule(match) + end +end + +local function append_match(string, pattern, rule, + + +local function lex(string) + for _, typename in ipairs(c_int_types) do + if (string.sub(string, 1, #typename) == typename) then + return + end +end + + +function bind(signature) + +end + + +return b |