isbear@23:
isbear@23: /* Copyright 2009 Myhailo Danylenko
isbear@23:
isbear@23: This code is free software: you can redistribute it and/or modify
isbear@23: it under the terms of the GNU General Public License as published by
isbear@23: the Free Software Foundation, either version 2 of the License, or
isbear@23: (at your option) any later version.
isbear@23:
isbear@23: This program is distributed in the hope that it will be useful,
isbear@23: but WITHOUT ANY WARRANTY; without even the implied warranty of
isbear@23: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
isbear@23: GNU General Public License for more details.
isbear@23:
isbear@23: You should have received a copy of the GNU General Public License
isbear@23: along with this program. If not, see . */
isbear@0:
isbear@0: #ifndef MISC_LUA_UTIL_H
isbear@0: #define MISC_LUA_UTIL_H
isbear@0:
isbear@0: #include
isbear@0:
isbear@4: // You can set this if anther type is required
isbear@0: #ifndef enum_value_t
isbear@0: #define enum_value_t int
isbear@0: #endif
isbear@0:
isbear@0: // Array of string2eunm_t's must be ended with pair { NULL, fallback_value }
isbear@0: typedef struct {
isbear@0: const char *string;
isbear@0: enum_value_t value;
isbear@0: } string2enum_t;
isbear@0:
isbear@0: // If not found, fallback_value is returned
isbear@0: enum_value_t string2enum (const char *string, const string2enum_t *set);
isbear@0: // If not found, NULL is returned
isbear@0: const char *enum2string (enum_value_t value, const string2enum_t *set);
isbear@0:
isbear@0: // returns result of string2enum on specified stack index, can handle plain numbers (no s2e called in this case)
isbear@0: enum_value_t luaL_checkenum (lua_State *L, int index, const string2enum_t *set);
isbear@0: // pushes onto a stack result of enum2string on a given value, if not recognized, pushes value as number
isbear@0: void luaL_pushenum (lua_State *L, enum_value_t value, const string2enum_t *set);
isbear@0:
isbear@0: // as luaL_checknum, but additionally handles tables as a multiple flags set.
isbear@0: // table can contain both array and hash key-value pairs
isbear@0: // hash entries are ORed with string2enum(key) if value resolves to lua true value
isbear@0: // array entries are always ORed with string2enum(value)
isbear@0: // eg { flag1, flag2, 16, flag3 = true, flag4 = { }, flag5 = nil } will set all flags except flag5 (and 16 too will be ORed)
isbear@0: enum_value_t luaL_checkenum_multi (lua_State *L, int index, const string2enum_t *set);
isbear@0: // pushes to stack table with all matched values from a set in a hash format
isbear@0: // eg { flag1 = true, flag2 = true, flag6 = true, 16 } - that's it, if some bits will not match, they will be passed as a first array element.
isbear@0: void luaL_pushenum_multi (lua_State *L, enum_value_t value, const string2enum_t *set);
isbear@0:
isbear@0: void *luaL_malloc (lua_State *L, size_t size);
isbear@0: void *luaL_realloc (lua_State *L, void *ptr, size_t osize, size_t nsize);
isbear@0: void luaL_free (lua_State *L, void *ptr);
isbear@0:
isbear@0: #endif
isbear@0: