소스 검색

Move subsystem access function to subsystem's pkg file, add global readonly property for each subsystem.

aster2013 12 년 전
부모
커밋
8ab5e56c9c

+ 11 - 2
Source/Engine/LuaScript/ToluaUtils.h

@@ -22,6 +22,7 @@
 
 #pragma once
 
+#include "Context.h"
 #include "OctreeQuery.h"
 #include "PhysicsWorld.h"
 #include "Vector2.h"
@@ -52,14 +53,14 @@ void SetContext(lua_State* L, Context* context);
 /// Return context.
 Context* GetContext(lua_State* L);
 
-/// Create new object.
+/// Create object.
 template<typename T> int ToluaNewObject(lua_State* tolua_S)
 {
     T* object = Mtolua_new(T(GetContext(tolua_S)));
     tolua_pushusertype(tolua_S, (void*)object,T::GetTypeNameStatic().CString());
     return 1;
 }
-/// Create new object with GC.
+/// Create object with GC.
 template<typename T> int ToluaNewObjectGC(lua_State* tolua_S)
 {
     T* object = Mtolua_new(T(GetContext(tolua_S)));
@@ -68,6 +69,14 @@ template<typename T> int ToluaNewObjectGC(lua_State* tolua_S)
     return 1;
 }
 
+/// Return subsystem.
+template<typename T> int ToluaGetSubsystem(lua_State* tolua_S)
+{
+    T* subsystem = GetContext(tolua_S)->GetSubsystem<T>();
+    tolua_pushusertype(tolua_S, (void*)subsystem, T::GetTypeNameStatic().CString());
+    return 1;
+}
+
 /// Check Lua table is Vector<T>.
 template<typename T> int ToluaIsVector(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
 /// Check Lua table is Vector<String>.

+ 14 - 0
Source/Engine/LuaScript/pkgs/Audio/Audio.pkg

@@ -42,3 +42,17 @@ class Audio : public Object
     tolua_readonly tolua_property__is_set bool initialized;
     tolua_property__get_set SoundListener* listener;
 };
+
+Audio* GetAudio();
+tolua_readonly tolua_property__get_set Audio* audio;
+
+${
+#define TOLUA_DISABLE_tolua_AudioLuaAPI_GetAudio00
+static int tolua_AudioLuaAPI_GetAudio00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<Audio>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_audio_ptr
+#define tolua_get_audio_ptr tolua_AudioLuaAPI_GetAudio00
+$}

+ 0 - 73
Source/Engine/LuaScript/pkgs/Core/Context.pkg

@@ -1,18 +1,4 @@
-$#include "Audio.h"
-$#include "Console.h"
 $#include "Context.h"
-$#include "DebugHud.h"
-$#include "Engine.h"
-$#include "FileSystem.h"
-$#include "Graphics.h"
-$#include "Input.h"
-$#include "Log.h"
-$#include "Network.h"
-$#include "LuaScript.h"
-$#include "Renderer.h"
-$#include "ResourceCache.h"
-$#include "Timer.h"
-$#include "UI.h"
 
 class Context
 {
@@ -25,20 +11,6 @@ Context* GetContext();
 Object* GetEventSender();
 EventHandler* GetEventHandler() const;
 
-Audio* GetAudio();
-Console* GetConsole();
-DebugHud* GetDebugHud();
-Engine* GetEngine();
-FileSystem* GetFileSystem();
-Graphics* GetGraphics();
-Input* GetInput();
-Log* GetLog();
-Network* GetNetwork();
-Renderer* GetRenderer();
-ResourceCache* GetCache();
-Time* GetTime();
-UI* GetUI();
-
 ${
 #define TOLUA_DISABLE_tolua_CoreLuaAPI_GetContext00
 static int tolua_CoreLuaAPI_GetContext00(lua_State* tolua_S)
@@ -63,49 +35,4 @@ static int tolua_CoreLuaAPI_GetEventHandler00(lua_State* tolua_S)
     tolua_pushusertype(tolua_S,(void*)tolua_ret,"EventHandler");
     return 1;
 }
-
-#define GET_SUBSYSTEM(subsystem) \
-static int tolua_CoreLuaAPI_Get ## subsystem ## 00(lua_State* tolua_S) \
-{ \
-  subsystem* tolua_ret = GetContext(tolua_S)->GetSubsystem<subsystem>(); \
-  tolua_pushusertype(tolua_S,(void*)tolua_ret,#subsystem); \
-  return 1; \
-}
-
-#define GET_SUBSYSTEM_RENAME(subsystem, newname) \
-static int tolua_CoreLuaAPI_Get ## newname ## 00(lua_State* tolua_S) \
-{ \
-  subsystem* tolua_ret = GetContext(tolua_S)->GetSubsystem<subsystem>(); \
-  tolua_pushusertype(tolua_S,(void*)tolua_ret,#subsystem); \
-  return 1; \
-}
-
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetAudio00
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetConsole00
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetDebugHud00
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetEngine00
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetFileSystem00
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetGraphics00
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetInput00
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetLog00
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetNetwork00
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetRenderer00
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetCache00
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetTime00
-#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetUI00
-
-GET_SUBSYSTEM(Audio)
-GET_SUBSYSTEM(Console)
-GET_SUBSYSTEM(DebugHud)
-GET_SUBSYSTEM(Engine)
-GET_SUBSYSTEM(FileSystem)
-GET_SUBSYSTEM(Graphics)
-GET_SUBSYSTEM(Input)
-GET_SUBSYSTEM(Log)
-GET_SUBSYSTEM(Network)
-GET_SUBSYSTEM(Renderer)
-GET_SUBSYSTEM_RENAME(ResourceCache, Cache)
-GET_SUBSYSTEM(Time)
-GET_SUBSYSTEM(UI)
-
 $}

+ 14 - 0
Source/Engine/LuaScript/pkgs/Core/Timer.pkg

@@ -17,3 +17,17 @@ class Time : public Object
     tolua_readonly tolua_property__get_set unsigned timerPeriod;
     tolua_readonly tolua_property__get_set float elapsedTime;
 };
+
+Time* GetTime();
+tolua_readonly tolua_property__get_set Time* time;
+
+${
+#define TOLUA_DISABLE_tolua_CoreLuaAPI_GetTime00
+static int tolua_CoreLuaAPI_GetTime00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<Time>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_time_ptr
+#define tolua_get_time_ptr tolua_CoreLuaAPI_GetTime00
+$}

+ 14 - 0
Source/Engine/LuaScript/pkgs/Engine/Console.pkg

@@ -26,3 +26,17 @@ class Console : public Object
     tolua_property__get_set unsigned numHistoryRows;
     tolua_readonly tolua_property__get_set unsigned historyPosition;
 };
+
+Console* GetConsole();
+tolua_readonly tolua_property__get_set Console* console;
+
+${
+#define TOLUA_DISABLE_tolua_EngineLuaAPI_GetConsole00
+static int tolua_EngineLuaAPI_GetConsole00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<Console>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_console_ptr
+#define tolua_get_console_ptr tolua_EngineLuaAPI_GetConsole00
+$}

+ 14 - 0
Source/Engine/LuaScript/pkgs/Engine/DebugHud.pkg

@@ -39,3 +39,17 @@ class DebugHud : public Object
     tolua_property__get_set float profilerInterval;
     tolua_property__get_set bool useRendererStats;
 };
+
+DebugHud* GetDebugHud();
+tolua_readonly tolua_property__get_set DebugHud* debugHud;
+
+${
+#define TOLUA_DISABLE_tolua_EngineLuaAPI_GetDebugHud00
+static int tolua_EngineLuaAPI_GetDebugHud00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<DebugHud>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_debugHud_ptr
+#define tolua_get_debugHud_ptr tolua_EngineLuaAPI_GetDebugHud00
+$}

+ 14 - 0
Source/Engine/LuaScript/pkgs/Engine/Engine.pkg

@@ -38,3 +38,17 @@ class Engine : public Object
     tolua_readonly tolua_property__is_set bool exiting;
     tolua_readonly tolua_property__is_set bool headless;
 };
+
+Engine* GetEngine();
+tolua_readonly tolua_property__get_set Engine* engine;
+
+${
+#define TOLUA_DISABLE_tolua_EngineLuaAPI_GetEngine00
+static int tolua_EngineLuaAPI_GetEngine00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<Engine>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_engine_ptr
+#define tolua_get_engine_ptr tolua_EngineLuaAPI_GetEngine00
+$}

+ 15 - 1
Source/Engine/LuaScript/pkgs/Graphics/Graphics.pkg

@@ -3,7 +3,7 @@ $#include "Graphics.h"
 class Graphics : public Object
 {
     void SetWindowTitle(const String windowTitle);
-	void SetWindowIcon(Image* windowIcon);
+    void SetWindowIcon(Image* windowIcon);
     void SetWindowPosition(const IntVector2& position);
     void SetWindowPosition(int x, int y);
 
@@ -79,3 +79,17 @@ class Graphics : public Object
     tolua_readonly tolua_property__get_set bool sRGBWriteSupport;
     tolua_readonly tolua_property__get_set IntVector2 desktopResolution;
 };
+
+Graphics* GetGraphics();
+tolua_readonly tolua_property__get_set Graphics* graphics;
+
+${
+#define TOLUA_DISABLE_tolua_GraphicsLuaAPI_GetGraphics00
+static int tolua_GraphicsLuaAPI_GetGraphics00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<Graphics>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_graphics_ptr
+#define tolua_get_graphics_ptr tolua_GraphicsLuaAPI_GetGraphics00
+$}

+ 14 - 0
Source/Engine/LuaScript/pkgs/Graphics/Renderer.pkg

@@ -204,3 +204,17 @@ class Renderer
     tolua_readonly tolua_property__get_set ShaderVariation* stencilVS;
     tolua_readonly tolua_property__get_set ShaderVariation* stencilPS;
 };
+
+Renderer* GetRenderer();
+tolua_readonly tolua_property__get_set Renderer* renderer;
+
+${
+#define TOLUA_DISABLE_tolua_GraphicsLuaAPI_GetRenderer00
+static int tolua_GraphicsLuaAPI_GetRenderer00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<Renderer>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_renderer_ptr
+#define tolua_get_renderer_ptr tolua_GraphicsLuaAPI_GetRenderer00
+$}

+ 12 - 0
Source/Engine/LuaScript/pkgs/IO/FileSystem.pkg

@@ -40,7 +40,19 @@ String GetInternalPath(const String pathName);
 String GetNativePath(const String pathName);
 bool IsAbsolutePath(const String pathName);
 
+FileSystem * GetFileSystem();
+tolua_readonly tolua_property__get_set FileSystem* fileSystem;
+
 ${
+#define TOLUA_DISABLE_tolua_IOLuaAPI_GetFileSystem00
+static int tolua_IOLuaAPI_GetFileSystem00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<FileSystem>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_fileSystem_ptr
+#define tolua_get_fileSystem_ptr tolua_IOLuaAPI_GetFileSystem00
+
 static const Vector<String>& FileSystemScanDir(const FileSystem* fileSystem, const String pathName, const String filter, unsigned flags, bool recursive)
 {
     static Vector<String> result;

+ 14 - 0
Source/Engine/LuaScript/pkgs/IO/Log.pkg

@@ -26,3 +26,17 @@ class Log : public Object
     tolua_property__get_set bool timeStamp;
     tolua_property__is_set bool quiet;
 };
+
+Log* GetLog();
+tolua_readonly tolua_property__get_set Log* log;
+
+${
+#define TOLUA_DISABLE_tolua_IOLuaAPI_GetLog00
+static int tolua_IOLuaAPI_GetLog00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<Log>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_log_ptr
+#define tolua_get_log_ptr tolua_IOLuaAPI_GetLog00
+$}

+ 14 - 0
Source/Engine/LuaScript/pkgs/Input/Input.pkg

@@ -73,3 +73,17 @@ class Input : public Object
     tolua_readonly tolua_property__has_set bool focus;
     tolua_readonly tolua_property__is_set bool minimized;
 };
+
+Input* GetInput();
+tolua_readonly tolua_property__get_set Input* input;
+
+${
+#define TOLUA_DISABLE_tolua_InputLuaAPI_GetInput00
+static int tolua_InputLuaAPI_GetInput00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<Input>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_input_ptr
+#define tolua_get_input_ptr tolua_InputLuaAPI_GetInput00
+$}

+ 14 - 0
Source/Engine/LuaScript/pkgs/Network/Network.pkg

@@ -44,3 +44,17 @@ class Network
     tolua_readonly tolua_property__is_set bool serverRunning;
     tolua_property__get_set String packageCacheDir;
 };
+
+Network* GetNetwork();
+tolua_readonly tolua_property__get_set Network* network;
+
+${
+#define TOLUA_DISABLE_tolua_NetworkLuaAPI_GetNetwork00
+static int tolua_NetworkLuaAPI_GetNetwork00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<Network>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_network_ptr
+#define tolua_get_network_ptr tolua_NetworkLuaAPI_GetNetwork00
+$}

+ 12 - 0
Source/Engine/LuaScript/pkgs/Resource/ResourceCache.pkg

@@ -32,7 +32,19 @@ class ResourceCache
     tolua_readonly tolua_property__get_set bool searchPackagesFirst;
 };
 
+ResourceCache* GetCache();
+tolua_readonly tolua_property__get_set ResourceCache* cache;
+
 ${
+#define TOLUA_DISABLE_tolua_ResourceLuaAPI_GetCache00
+static int tolua_ResourceLuaAPI_GetCache00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<ResourceCache>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_cache_ptr
+#define tolua_get_cache_ptr tolua_ResourceLuaAPI_GetCache00
+
 static File* ResourceCacheGetFile(ResourceCache* cache, const String& fileName)
 {
     SharedPtr<File> file = cache->GetFile(fileName);

+ 14 - 0
Source/Engine/LuaScript/pkgs/UI/UI.pkg

@@ -69,3 +69,17 @@ class UI : public Object
     tolua_property__get_set bool forceAutoHint;
     tolua_readonly tolua_property__has_set bool modalElement;
 };
+
+UI* GetUI();
+tolua_readonly tolua_property__get_set UI* ui;
+
+${
+#define TOLUA_DISABLE_tolua_UILuaAPI_GetUI00
+static int tolua_UILuaAPI_GetUI00(lua_State* tolua_S)
+{
+    return ToluaGetSubsystem<UI>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_get_ui_ptr
+#define tolua_get_ui_ptr tolua_UILuaAPI_GetUI00
+$}