0
|
1 |
|
|
2 |
#ifndef MISC_LUA_UTIL_H |
|
3 |
#define MISC_LUA_UTIL_H |
|
4 |
|
|
5 |
#include <lua.h> |
|
6 |
|
|
7 |
// You can set this if anther type is required |
|
8 |
#ifndef enum_value_t |
|
9 |
#define enum_value_t int |
|
10 |
#endif |
|
11 |
|
|
12 |
// Array of string2eunm_t's must be ended with pair { NULL, fallback_value } |
|
13 |
typedef struct { |
|
14 |
const char *string; |
|
15 |
enum_value_t value; |
|
16 |
} string2enum_t; |
|
17 |
|
|
18 |
// If not found, fallback_value is returned |
|
19 |
enum_value_t string2enum (const char *string, const string2enum_t *set); |
|
20 |
// If not found, NULL is returned |
|
21 |
const char *enum2string (enum_value_t value, const string2enum_t *set); |
|
22 |
|
|
23 |
// returns result of string2enum on specified stack index, can handle plain numbers (no s2e called in this case) |
|
24 |
enum_value_t luaL_checkenum (lua_State *L, int index, const string2enum_t *set); |
|
25 |
// pushes onto a stack result of enum2string on a given value, if not recognized, pushes value as number |
|
26 |
void luaL_pushenum (lua_State *L, enum_value_t value, const string2enum_t *set); |
|
27 |
|
|
28 |
// as luaL_checknum, but additionally handles tables as a multiple flags set. |
|
29 |
// table can contain both array and hash key-value pairs |
|
30 |
// hash entries are ORed with string2enum(key) if value resolves to lua true value |
|
31 |
// array entries are always ORed with string2enum(value) |
|
32 |
// eg { flag1, flag2, 16, flag3 = true, flag4 = { }, flag5 = nil } will set all flags except flag5 (and 16 too will be ORed) |
|
33 |
enum_value_t luaL_checkenum_multi (lua_State *L, int index, const string2enum_t *set); |
|
34 |
// pushes to stack table with all matched values from a set in a hash format |
|
35 |
// 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. |
|
36 |
void luaL_pushenum_multi (lua_State *L, enum_value_t value, const string2enum_t *set); |
|
37 |
|
|
38 |
void *luaL_malloc (lua_State *L, size_t size); |
|
39 |
void *luaL_realloc (lua_State *L, void *ptr, size_t osize, size_t nsize); |
|
40 |
void luaL_free (lua_State *L, void *ptr); |
|
41 |
|
|
42 |
#endif |
|
43 |
|