ArtMOO
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
G:/dev/qt/MOO/ServerCore/lua_moo.h
Go to the documentation of this file.
00001 #ifndef LUA_MOO_H
00002 #define LUA_MOO_H
00003 
00004 #include <cstdio>
00005 #include <iostream>
00006 
00007 #include <QVector>
00008 
00009 #include "mooglobal.h"
00010 #include "lua_utilities.h"
00011 
00012 class lua_moo
00013 {
00014 private:
00015         static const luaL_Reg                           mLuaGlobal[];
00016         static const luaL_Reg                           mLuaMeta[];
00017         static const luaL_Reg                           mLuaStatic[];
00018         static const luaL_Reg                           mLuaGetFunc[];
00019 
00020         static LuaMap                                           mLuaFun;
00021         static LuaMap                                           mLuaGet;
00022         static LuaMap                                           mLuaSet;
00023 
00024         static void luaRegisterAllStates( lua_State *L );
00025 
00026         static void luaRegisterState( lua_State *L );
00027 
00028         static int luaGlobalIndex( lua_State *L );
00029 
00030         static int luaGet( lua_State *L );
00031         static int luaSet( lua_State *L );
00032 
00033         static int luaNotify( lua_State *L );
00034         static int luaRoot( lua_State *L );
00035         static int luaPass( lua_State *L );
00036         static int luaEval( lua_State *L );
00037         static int luaDebug( lua_State *L );
00038         static int luaPlayers( lua_State *L );
00039 
00040         static int luaPanic( lua_State *L );
00041 
00042         static void typeDump( lua_State *L, const int i )
00043         {
00044                 int t = lua_type(L, i);
00045 
00046                 switch (t)
00047                 {
00048                         case LUA_TSTRING:  /* strings */
00049                                 printf( "%d: `%s'", i, lua_tostring(L, i));
00050                                 break;
00051 
00052                         case LUA_TBOOLEAN:  /* booleans */
00053                                 printf( "%d: %s", i, lua_toboolean(L, i) ? "true" : "false");
00054                                 break;
00055 
00056                         case LUA_TNUMBER:  /* numbers */
00057                                 printf("%d: %g", i, lua_tonumber(L, i));
00058                                 break;
00059 
00060                         case LUA_TTABLE:
00061                                 tableDump( L, i );
00062                                 break;
00063 
00064                         default:  /* other values */
00065                                 printf("%d: %s", i, lua_typename(L, t));
00066                                 break;
00067 
00068                 }
00069         }
00070 
00071         static void tableDump( lua_State *L, const int t )
00072         {
00073                 //printf( "enter: %d\n", lua_gettop( L ) );
00074 
00075                 printf( "table\n{\n" );
00076 
00077                 lua_pushnil( L );               // first key
00078 
00079                 while( lua_next( L, t ) != 0 )
00080                 {
00081                         typeDump( L, -2 );
00082 
00083                         printf( "%s", lua_typename( L, lua_type( L, -1 ) ) );
00084 
00085                         //typeDump( L, -1 );
00086 
00087                         printf( "\n" );
00088 
00089                         /* removes 'value'; keeps 'key' for next iteration */
00090 
00091                         lua_pop( L, 1 );
00092                 }
00093 
00094                 printf( "}\n" );
00095 
00096                 //printf( "exit: %d\n", lua_gettop( L ) );
00097         }
00098 
00099         static void initialise( void );
00100 
00101 public:
00102         static void initialiseAll( void );
00103 
00104         static void luaNewState( lua_State *L );
00105 
00106         static void luaSetEnv( lua_State *L );
00107 
00108         static void stackDump (lua_State *L)
00109         {
00110                 int i;
00111                 int top = lua_gettop(L);
00112 
00113                 for (i = 1; i <= top; i++) /* repeat for each level */
00114                 {
00115                         typeDump( L, i );
00116 
00117                         printf("  ");  /* put a separator */
00118                 }
00119 
00120                 printf("\n");  /* end the listing */
00121 
00122                 std::cout.flush();
00123         }
00124 
00125         static void addFunctions( const luaL_reg *pFuncs );
00126         static void addGet( const luaL_reg *pFuncs );
00127         static void addSet( const luaL_reg *pFuncs );
00128 };
00129 
00130 #endif // LUA_MOO_H