diff options
author | sanine-a <sanine.not@pm.me> | 2020-12-19 00:34:45 -0600 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-12-19 00:34:45 -0600 |
commit | 86e562d59eb26f305cb183d29b82123f944dd328 (patch) | |
tree | b641fd53364b2ad60af256eaf16811f8495c8922 /src/honey_lua.c | |
parent | 91b914bc0eb97a76f2c3a1caa64fdfde29ca16a1 (diff) |
add additional cairo texture config functions
Diffstat (limited to 'src/honey_lua.c')
-rw-r--r-- | src/honey_lua.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/honey_lua.c b/src/honey_lua.c index 50a9710..4b83f27 100644 --- a/src/honey_lua.c +++ b/src/honey_lua.c @@ -91,7 +91,55 @@ void honey_lua_throw_error(lua_State* L, } lua_error(L); } + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +bool honey_string_to_enum(int* k, char* string, int n, ...) +{ + va_list args; + va_start(args, n); + + bool success = false; + + for (int i=0; i<n; i++) { + const char* str = va_arg(args, const char*); + int val = va_arg(args, const char*); + + if (strcmp(str, string) == 0) { + *k = val; + success = true; + break; + } + } + + va_end(args); + return success; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +bool honey_enum_to_string(char** string, int k, int n, ...) +{ + va_list args; + va_start(args, n); + + bool success = false; + for (int i=0; i<n; i++) { + const char* str = va_arg(args, const char*); + int val = va_arg(args, const char*); + + if (k == val) { + *string = str; + success = true; + break; + } + } + + va_end(args); + return success; +} + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Argument parsing functions |