Skip to content

Commit

Permalink
restore the "next" functionnality on structs
Browse files Browse the repository at this point in the history
  • Loading branch information
boucman committed Aug 17, 2014
1 parent 9d9412a commit 4796ff0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
32 changes: 29 additions & 3 deletions lautoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ void luaA_struct_type(lua_State* L, luaA_Type type) {
lua_newtable(L);
lua_settable(L, -3);
lua_pop(L, 1);
lua_getfield(L, LUA_REGISTRYINDEX, LUAA_REGISTRYPREFIX "luaA_structs_offset");
lua_getfield(L, LUA_REGISTRYINDEX, LUAA_REGISTRYPREFIX "structs_offset");
lua_pushinteger(L, type);
lua_newtable(L);
lua_settable(L, -3);
Expand All @@ -715,7 +715,7 @@ void luaA_struct_member_type(lua_State* L, luaA_Type type, const char* member, l
lua_pushstring(L, member); lua_setfield(L, -2, "name");

lua_setfield(L, -2, member);
lua_getfield(L, LUA_REGISTRYINDEX, LUAA_REGISTRYPREFIX "luaA_structs_offset");
lua_getfield(L, LUA_REGISTRYINDEX, LUAA_REGISTRYPREFIX "structs_offset");
lua_pushinteger(L, offset);
lua_getfield(L, -3, member);
lua_settable(L,-3);
Expand Down Expand Up @@ -747,7 +747,6 @@ int luaA_struct_push_type(lua_State* L, luaA_Type type, const void* c_in) {
lua_gettable(L, -2);

if (!lua_isnil(L, -1)) {

lua_remove(L, -2);
lua_newtable(L);

Expand Down Expand Up @@ -799,6 +798,33 @@ void luaA_struct_to_type(lua_State* L, luaA_Type type, void* c_out, int index) {

}

const char* luaA_struct_next_member_name_type(lua_State* L, luaA_Type type, const char* member) {

lua_getfield(L, LUA_REGISTRYINDEX, LUAA_REGISTRYPREFIX "structs");
lua_pushinteger(L, type);
lua_gettable(L, -2);

if(!lua_isnil(L,-1)) {

if(!member) {
lua_pushnil(L);
} else {
lua_pushstring(L,member);
}
if(!lua_next(L,-2)) {
lua_pop(L,2);
return LUAA_INVALID_MEMBER_NAME;
}
const char* result = lua_tostring(L,-2);
lua_pop(L,4);
return result;
}

lua_pop(L, 2);
lua_pushfstring(L, "luaA_struct_next_member: Struct '%s' not registered!", luaA_typename(L, type));
lua_error(L);
return NULL;//can't be reached
}
/*
** Enums
*/
Expand Down
4 changes: 4 additions & 0 deletions lautoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void luaA_to_void_ptr(lua_State* L, luaA_Type, void* c_out, int index);
/*
** Structs
*/
#define LUAA_INVALID_MEMBER_NAME NULL

#define luaA_struct(L, type) luaA_struct_type(L, luaA_type(L, type))
#define luaA_struct_member(L, type, member, member_type) luaA_struct_member_type(L, luaA_type(L, type), #member, luaA_type(L, member_type), offsetof(type, member))
Expand All @@ -133,6 +134,7 @@ void luaA_to_void_ptr(lua_State* L, luaA_Type, void* c_out, int index);
#define luaA_struct_typeof_member_name(L, type, member) luaA_struct_typeof_member_name_type(L, luaA_type(L, type), member)

#define luaA_struct_registered(L, type) luaA_struct_registered_type(L, luaA_type(L, type))
#define luaA_struct_next_member_name(L, type, member) luaA_struct_next_member_name_type(L, luaA_type(L,type), member)

void luaA_struct_type(lua_State* L, luaA_Type type);
void luaA_struct_member_type(lua_State* L, luaA_Type type, const char* member, luaA_Type member_type, size_t offset);
Expand All @@ -153,6 +155,8 @@ luaA_Type luaA_struct_typeof_member_name_type(lua_State* L, luaA_Type type, cons

bool luaA_struct_registered_type(lua_State* L, luaA_Type type);

const char* luaA_struct_next_member_name_type(lua_State* L, luaA_Type type, const char* member);

/*
** Enums
*/
Expand Down

0 comments on commit 4796ff0

Please sign in to comment.