Everything builds and works again.
[fail.git] / include / services / lua / module.h
blob61b9408098755c94a0b4149126a4a530967c17e7
1 #ifndef AWFUL_LUA_MODULE_H
2 #define AWFUL_LUA_MODULE_H
4 namespace awful { namespace LuaImpl
5 {
6 struct ModuleVisitor
8 ModuleVisitor( lua_State* pLS_ ) :
9 pLS( pLS_ ),
10 bAtGlobalScope( true )
14 // Called for each nested namespace until the namespace we're interested in.
15 // Create all intermediate namespace tables as needed.
16 // Also build the module name in the form module.submodule.subsubmodule
17 // to be able to set the package.loaded properly.
18 void QualifiedNameComponent( const char* pName_ )
20 if( bAtGlobalScope )
22 FullModuleName = pName_;
23 lua_getglobal( pLS, pName_ );
25 else
27 FullModuleName += '.';
28 FullModuleName += pName_;
29 lua_getfield( pLS, -1, pName_ );
32 if( lua_isnil( pLS, -1 ) )
34 lua_pop( pLS, 1 );
35 lua_newtable( pLS );
36 lua_pushvalue( pLS, -1 );
38 if( bAtGlobalScope )
40 lua_setglobal( pLS, pName_ );
42 else
44 lua_setfield( pLS, -3, pName_ );
45 lua_remove( pLS, -3 );
49 bAtGlobalScope = false;
52 template< class C > void Class()
54 ClassStuff< C >::Setup();
57 template< class C > void Struct()
59 StructStuff< C >::Setup();
62 lua_State* pLS;
63 bool bAtGlobalScope;
64 std::string FullModuleName;
68 #endif