Okay I solved it.
lua_pushglobaltable(L); // Get global table
lua_pushnil(L); // put a nil key on stack
while (lua_next(L,-2) != 0) { // key(-1) is replaced by the next key(-1) in table(-2)
name = lua_tostring(L,-2); // Get key(-2) name
lua_pop(L,1); // remove value(-1), now key on top at(-1)
}
lua_pop(L,1); // remove global table(-1)
When lua_next()
can't find more entries the key name is popped leaving the table on top(-1).
Next problem would be to distinguish my own globals from the rest of the table entries...