I just comitted my get_enum code to a modded trunk in my branch. I had to do some extra things to get LuaGL trunk to compile on OSX and some additional things to get it to work as a C++ file. It works with the following mask techniques:
15a16,19
>
> #if defined (__APPLE__) || defined (OSX)
> #include <stdlib.h>
> #else
16a21,25
> #endif
>
> #ifdef __cplusplus
> extern "C" {
> #endif
19a29,36
> #ifdef __cplusplus
> }
> #endif
>
> #include <string>
>
> using namespace std;
>
21a39,41
> #define LUA_GL_STRING_TO_ENUM_TABLE "LuaGL_string_to_enum_table"
> #define LUA_GL_ENUM_TO_STRING_TABLE "LuaGL_enum_to_string_table"
>
32c52
< static GLenum get_enum(const char *str, int n)
---
> GLenum get_enum(lua_State *L, const char *key)
34c54
< int i = 0;
---
> GLenum val;
36,39c56,57
< while(gl_str[i].str != 0)
< {
< if(strncmp(str, gl_str[i].str, n) == 0 && gl_str[i].str[n] == 0)
< return gl_str[i].value;
---
> lua_getfield(L, LUA_REGISTRYINDEX, LUA_GL_STRING_TO_ENUM_TABLE);
> lua_getfield(L, -1, key);
41c59,60
< i++;
---
> if(lua_isnil(L, -1)) {
> val = ENUM_ERROR;
43c62,63
< return ENUM_ERROR;
---
> else {
> val = (GLenum)lua_tointeger(L, -1);
45,49c65
< static GLenum get_gl_enum(lua_State *L, int index)
< {
< unsigned int i;
< const char *str = lua_tostring(L, index);
< GLenum temp = 0, ret = 0;
---
> lua_pop(L, 2); //pop value and enum table
51c67,70
< for(i = 0; i < strlen(str); i++)
---
> return val;
> }
>
> GLenum get_gl_mask_enum(lua_State *L, const char *key, char token)
53c72,77
< if(str[i] == ',')
---
> GLenum val = 0;
> string mask(key);
> size_t pos = 0, substr_start = 0, last_pos = 0;
>
> pos = mask.find(token, substr_start);
> while(last_pos != string::npos)
55,57c79,90
< temp = get_enum(str, i);
< if(temp != ENUM_ERROR)
< ret |= temp;
---
> int end_off = 0;
>
> //check for leading and trailing spaces
> if(mask[substr_start] == ' ') {
> substr_start++;
> }
>
> if(mask[pos - substr_start - 1] == ' ') {
> end_off = 1;
> }
>
> string bit = mask.substr(substr_start, pos - substr_start - end_off);
59,60c92,96
< str += i+1;
< i = 0;
---
> val |= get_enum(L, bit.c_str());
>
> substr_start = pos+1;
> last_pos = pos;
> pos = mask.find(token, substr_start);
61a98,99
>
> return val;
63d100
< temp = get_enum(str, strlen(str));
65c102
< if(temp == ENUM_ERROR)
---
> LUAGL_API GLenum get_gl_enum(lua_State *L, int index)
67,69c104,116
< if(ret == 0)
< return ENUM_ERROR;
< return ret;
---
> const char *key = lua_tostring(L, index);
> GLenum val = 0;
> char token1 = ',', token2 = '|' ;
>
> //detect if multiple enums as a bit mask
> if(strchr(key, token1)) {
> val = get_gl_mask_enum(L, key, token1);
> }
> else if(strchr(key, token2)) {
> val = get_gl_mask_enum(L, key, token2);
> }
> else {
> val = get_enum(L, key);
72c119
< return ret | temp;
---
> return val;
75c122
< static const char *get_str_gl_enum(GLenum num)
---
> LUAGL_API const char *get_str_gl_enum(lua_State *L, GLenum num)
77c124
< unsigned int i = 0;
---
> const char *val;
79,82c126,130
< while(gl_str[i].str != 0)
< {
< if(num == gl_str[i].value)
< return gl_str[i].str;
---
> lua_getfield(L, LUA_REGISTRYINDEX, LUA_GL_ENUM_TO_STRING_TABLE);
> lua_pushnumber(L, num);
> lua_gettable(L, -2);
> val = lua_tostring(L, -1);
> lua_pop(L, 2); //pop value and enum table
84,86c132
< i++;
< }
< return NULL;
---
> return val;
202c248
< static int get_array2d(lua_State *L, int index, GLdouble **array, int *size)
---
> static int get_array2d(lua_State *L, int index, GLdouble **array, GLint *size)
215c261
< *size = luaL_getn(L, -1);
---
> *size = (GLint)luaL_getn(L, -1);
238c284
< static int get_array2f(lua_State *L, int index, GLfloat **array, int *size)
---
> static int get_array2f(lua_State *L, int index, GLfloat **array, GLsizei *size)
251c297
< *size = luaL_getn(L, -1);
---
> *size = (GLsizei)luaL_getn(L, -1);
526,529d571
< const char *arg;
< const char *delims = "|,";
< char arg_buffer[256];
< char *result = NULL;
532,549c574,576
< // test argument type
< if(lua_type(L, 1) != LUA_TSTRING) {
< script_error(L, "incorrect argument to function 'gl.Clear'");
< }
<
< arg = lua_tostring(L, 1);
<
< if(strlen(arg) > 256) {
< script_error(L, "incorrect argument to function 'gl.Clear'");
< }
<
< strcpy(arg_buffer, arg);
< result = strtok(arg_buffer, delims);
< while( result != NULL ) {
< printf("result: %s\n", result);
< result = strtok(NULL, delims);
< }
<
---
> /* test argument type */
> if(!lua_isstring(L, 1))
> luaL_error(L, "incorrect argument to function 'gl.Clear'");
553,556c580,582
< // test argument
< if(e == ENUM_ERROR) {
< script_error(L, "incorrect string argument to function 'gl.Clear'");
< }
---
> /* test argument */
> if(e == ENUM_ERROR)
> luaL_error(L, "incorrect string argument to function 'gl.Clear'");
557a584
> /* call opengl function */
1418c1445
< static gl_front_face(lua_State *L)
---
> static int gl_front_face(lua_State *L)
1503c1530
< int mask;
---
> GLint mask;
1641c1668
< str = get_str_gl_enum(params[i]);
---
> str = get_str_gl_enum(L, params[i]);
1766c1793
< lua_pushstring(L, get_str_gl_enum(error));
---
> lua_pushstring(L, get_str_gl_enum(L, error));
1950c1977
< int size;
---
> GLint size;
2020c2047
< glGetPointerv(e, (void *)&flags);
---
> glGetPointerv(e, (GLvoid **)&flags);
2035c2062
< glGetPointerv(e, (void *)¶ms);
---
> glGetPointerv(e, (GLvoid **)¶ms);
2096c2123
< int e2;
---
> GLint e2;
2113c2140
< lua_pushstring(L, get_str_gl_enum(e2));
---
> lua_pushstring(L, get_str_gl_enum(L, e2));
2142c2169
< int e3;
---
> GLint e3;
2160c2187
< lua_pushstring(L, get_str_gl_enum(e3));
---
> lua_pushstring(L, get_str_gl_enum(L, e3));
2183c2210
< int width, height, level;
---
> GLint width, height, level;
2258c2285
< int e;
---
> GLint e;
2293c2320
< lua_pushstring(L, get_str_gl_enum(e));
---
> lua_pushstring(L, get_str_gl_enum(L, e));
2412c2439
< static gl_is_list(lua_State *L)
---
> static int gl_is_list(lua_State *L)
2425c2452
< static gl_is_texture(lua_State *L)
---
> static int gl_is_texture(lua_State *L)
4108a4136,4139
> #ifdef __cplusplus
> extern "C" {
> #endif
>
4110a4142,4172
>
> //make sting_to_enum table
> lua_pushstring(L, LUA_GL_STRING_TO_ENUM_TABLE);
> lua_newtable(L);
> {
> int i=0;
> while(gl_str[i].str)
> {
> lua_pushstring(L, gl_str[i].str); //strings as enum keys
> lua_pushinteger(L, gl_str[i].value); //enum value as values
> lua_settable(L, -3); //set table with (key, value) pair
> i++;
> }
> }
> lua_settable(L, LUA_REGISTRYINDEX);
>
> //make enum_to_string table (not unique)
> lua_pushstring(L, LUA_GL_ENUM_TO_STRING_TABLE);
> lua_newtable(L);
> {
> int i=0;
> while(gl_str[i].str)
> {
> lua_pushinteger(L, gl_str[i].value); //enum value as keys
> lua_pushstring(L, gl_str[i].str); //strings as enum values
> lua_settable(L, -3); //set table with (key, value) pair
> i++;
> }
> }
> lua_settable(L, LUA_REGISTRYINDEX);
>
4112a4175,4178
>
> #ifdef __cplusplus
> }
> #endif