summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Data/DefaultContent/Libraries/GameLab/Events/Event.lua2
-rw-r--r--Editor/GUI/GUIWindow.cpp3
-rw-r--r--Projects/VisualStudio/Editor/Editor.vcxproj6
-rw-r--r--Projects/VisualStudio/Editor/Editor.vcxproj.filters18
-rw-r--r--Runtime/Events/Event.cpp1
-rw-r--r--Runtime/Events/Event.h8
-rw-r--r--Runtime/Lua/LuaBind/LuaBind.h1
-rw-r--r--Runtime/Lua/LuaBind/LuaBindInvoker.cpp4
-rw-r--r--Runtime/Lua/LuaBind/LuaBindLFunction.cpp63
-rw-r--r--Runtime/Lua/LuaBind/LuaBindLFunction.h26
-rw-r--r--Runtime/Lua/LuaBind/LuaBindState.cpp30
-rw-r--r--Runtime/Lua/LuaBind/LuaBindState.h2
-rw-r--r--Runtime/Lua/LuaHelper.cpp28
-rw-r--r--Runtime/Lua/LuaHelper.h5
-rw-r--r--Runtime/Scripting/RuntimeScriptingManager.h22
-rw-r--r--Runtime/Scripting/ScriptGlobals.h10
-rw-r--r--Runtime/Scripting/ScriptingManager.cpp14
17 files changed, 231 insertions, 12 deletions
diff --git a/Data/DefaultContent/Libraries/GameLab/Events/Event.lua b/Data/DefaultContent/Libraries/GameLab/Events/Event.lua
index 37fbc84..214d61e 100644
--- a/Data/DefaultContent/Libraries/GameLab/Events/Event.lua
+++ b/Data/DefaultContent/Libraries/GameLab/Events/Event.lua
@@ -7,4 +7,4 @@ Event.SetCurrentEvent = function(evt)
Event.current = evt
end
-return Event \ No newline at end of file
+return Event \ No newline at end of file
diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp
index 5aa598d..94dfe33 100644
--- a/Editor/GUI/GUIWindow.cpp
+++ b/Editor/GUI/GUIWindow.cpp
@@ -5,6 +5,7 @@
#include "Editor/Win/Win.h"
#include "Runtime/Math/Math.h"
#include "Runtime/Events/InputEvent.h"
+#include "Runtime/Scripting/ScriptingManager.h"
using namespace LuaBind;
@@ -261,6 +262,8 @@ void GUIWindow::ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam)
{
InputEvent ie(message, wParam, lParam, m_Handle);
+ SCRIPT_GLOBAL.setCurrentEvent.Invoke(0);
+
LuaBind::State state = GetVM()->GetCurThread();
LuaBind::MemberInvoker invoker = LuaBind::MemberInvoker(state, this);
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj
index dc727bb..6994ee6 100644
--- a/Projects/VisualStudio/Editor/Editor.vcxproj
+++ b/Projects/VisualStudio/Editor/Editor.vcxproj
@@ -176,6 +176,7 @@
<ClCompile Include="..\..\..\Editor\Win\Win.cpp" />
<ClCompile Include="..\..\..\Runtime\Common\DataBuffer.cpp" />
<ClCompile Include="..\..\..\Runtime\Debug\Log.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Events\Event.cpp" />
<ClCompile Include="..\..\..\Runtime\Events\InputEvent.cpp" />
<ClCompile Include="..\..\..\Runtime\FileSystem\File.cpp" />
<ClCompile Include="..\..\..\Runtime\FileSystem\FileJobs.cpp" />
@@ -213,6 +214,7 @@
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindEnum.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindHelper.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindInvoker.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindLFunction.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindMemberRef.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindRef.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindRefTable.cpp" />
@@ -237,6 +239,7 @@
<ClCompile Include="..\..\..\Runtime\Scripting\Rendering\Shader.bind.cpp" />
<ClCompile Include="..\..\..\Runtime\Scripting\Rendering\Texture.bind.cpp" />
<ClCompile Include="..\..\..\Runtime\Scripting\Resource\Resource.bind.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Scripting\ScriptingManager.cpp" />
<ClCompile Include="..\..\..\Runtime\Threading\Job.cpp" />
<ClCompile Include="..\..\..\Runtime\Threading\JobSystem.cpp" />
<ClCompile Include="..\..\..\Runtime\Threading\Mutex.cpp" />
@@ -266,6 +269,7 @@
<ClInclude Include="..\..\..\Editor\Win\Win.h" />
<ClInclude Include="..\..\..\Runtime\Common\DataBuffer.h" />
<ClInclude Include="..\..\..\Runtime\Debug\Log.h" />
+ <ClInclude Include="..\..\..\Runtime\Events\Event.h" />
<ClInclude Include="..\..\..\Runtime\Events\InputEvent.h" />
<ClInclude Include="..\..\..\Runtime\Events\KeyCode.h" />
<ClInclude Include="..\..\..\Runtime\FileSystem\File.h" />
@@ -335,7 +339,9 @@
<ClInclude Include="..\..\..\Runtime\Profiling\Profiler.h" />
<ClInclude Include="..\..\..\Runtime\Rendering\DynamicMesh.h" />
<ClInclude Include="..\..\..\Runtime\Rendering\Quad.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\ScriptGlobals.h" />
<ClInclude Include="..\..\..\Runtime\Scripting\ScriptingChecks.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\RuntimeScriptingManager.h" />
<ClInclude Include="..\..\..\Runtime\Threading\Job.h" />
<ClInclude Include="..\..\..\Runtime\Threading\JobSystem.h" />
<ClInclude Include="..\..\..\Runtime\Threading\Mutex.h" />
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters
index 84ad96b..7b7e549 100644
--- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters
+++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters
@@ -412,6 +412,15 @@
<ClCompile Include="..\..\..\Runtime\Events\InputEvent.cpp">
<Filter>Runtime\Events</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindLFunction.cpp">
+ <Filter>Runtime\Lua\LuaBind</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Events\Event.cpp">
+ <Filter>Runtime\Events</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Scripting\ScriptingManager.cpp">
+ <Filter>Runtime\Scripting</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\Editor\GUI\Dock.h">
@@ -738,6 +747,15 @@
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindLFunction.h">
<Filter>Runtime\Lua\LuaBind</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Events\Event.h">
+ <Filter>Runtime\Events</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Scripting\ScriptGlobals.h">
+ <Filter>Runtime\Scripting</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Scripting\RuntimeScriptingManager.h">
+ <Filter>Runtime\Scripting</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.inc">
diff --git a/Runtime/Events/Event.cpp b/Runtime/Events/Event.cpp
new file mode 100644
index 0000000..642094d
--- /dev/null
+++ b/Runtime/Events/Event.cpp
@@ -0,0 +1 @@
+#include "Event.h"
diff --git a/Runtime/Events/Event.h b/Runtime/Events/Event.h
new file mode 100644
index 0000000..f348ece
--- /dev/null
+++ b/Runtime/Events/Event.h
@@ -0,0 +1,8 @@
+#pragma once
+
+
+class Event
+{
+public:
+
+};
diff --git a/Runtime/Lua/LuaBind/LuaBind.h b/Runtime/Lua/LuaBind/LuaBind.h
index 2a73c98..8e8c6b1 100644
--- a/Runtime/Lua/LuaBind/LuaBind.h
+++ b/Runtime/Lua/LuaBind/LuaBind.h
@@ -13,5 +13,6 @@
#include "LuaBindInvoker.h"
#include "LuaBindTable.h"
#include "LuaBindLClass.h"
+#include "LuaBindLFunction.h"
#endif \ No newline at end of file
diff --git a/Runtime/Lua/LuaBind/LuaBindInvoker.cpp b/Runtime/Lua/LuaBind/LuaBindInvoker.cpp
index bd12e5c..d6780d7 100644
--- a/Runtime/Lua/LuaBind/LuaBindInvoker.cpp
+++ b/Runtime/Lua/LuaBind/LuaBindInvoker.cpp
@@ -105,7 +105,7 @@ namespace LuaBind
}
lua_replace(state, -2);
lua_insert(state, -1 - argc);
- state.Call(argc, nReturns, onErrorOccured);
+ state.Call(argc, nReturns);
}
-}
+} \ No newline at end of file
diff --git a/Runtime/Lua/LuaBind/LuaBindLFunction.cpp b/Runtime/Lua/LuaBind/LuaBindLFunction.cpp
new file mode 100644
index 0000000..b468897
--- /dev/null
+++ b/Runtime/Lua/LuaBind/LuaBindLFunction.cpp
@@ -0,0 +1,63 @@
+#include "LuaBindLFunction.h"
+#include "LuaBindHelper.h"
+
+namespace LuaBind
+{
+
+ LuaFunction::LuaFunction(const char* func)
+ {
+ method = func;
+ }
+
+ void LuaFunction::operator = (const char* func)
+ {
+ method = func;
+ }
+
+ void LuaFunction::AddInt(State& state, int n)
+ {
+ state.Push(n);
+ ++argc;
+ }
+
+ void LuaFunction::AddFloat(State& state, float n)
+ {
+ state.Push(n);
+ ++argc;
+ }
+
+ void LuaFunction::AddNil(State& state)
+ {
+ state.PushNil();
+ ++argc;
+ }
+
+ void LuaFunction::AddBool(State& state, bool b)
+ {
+ state.Push(b);
+ ++argc;
+ }
+
+ void LuaFunction::AddString(State& state, const char* str)
+ {
+ state.Push(str);
+ ++argc;
+ }
+
+ void LuaFunction::AddTable(State& state, INativeTable& tb)
+ {
+ tb.CastToTable(state);
+ ++argc;
+ }
+
+ void LuaFunction::Invoke(State& state, int nReturns)
+ {
+ if (state.GetGlobalField(method))
+ {
+ int funcIdx = -1 - argc;
+ lua_replace(state, funcIdx);
+ state.Call(argc, nReturns);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/Runtime/Lua/LuaBind/LuaBindLFunction.h b/Runtime/Lua/LuaBind/LuaBindLFunction.h
index 1ad6fa0..5c4346b 100644
--- a/Runtime/Lua/LuaBind/LuaBindLFunction.h
+++ b/Runtime/Lua/LuaBind/LuaBindLFunction.h
@@ -3,19 +3,29 @@
namespace LuaBind
{
- struct LuaFunction : public GlobalInvoker
+ struct LuaFunction
{
const char* method; // full name
- LuaFunction(lua_State* L, const char* func)
- : GlobalInvoker(L)
- , method(func)
- {}
+ LuaFunction(const char* func=NULL);
+ void operator = (const char* func);
- void Invoke(int nReturns) override
- {
+ void AddInt(State& state, int n);
+ void AddFloat(State& state, float n);
+ void AddNil(State& state);
+ void AddBool(State& state, bool b);
+ void AddString(State& state, const char* str);
+ void AddTable(State& state, INativeTable& tb);
+ template<class T>
+ void AddUserdata(State& state, NativeClass<T>& udata) {
+ udata.PushUserdata(state);
+ ++argc;
+ }
- }
+ void Invoke(State& state, int nReturns);
+
+ private:
+ int argc;
};
} \ No newline at end of file
diff --git a/Runtime/Lua/LuaBind/LuaBindState.cpp b/Runtime/Lua/LuaBind/LuaBindState.cpp
index 92e46cd..3fefa52 100644
--- a/Runtime/Lua/LuaBind/LuaBindState.cpp
+++ b/Runtime/Lua/LuaBind/LuaBindState.cpp
@@ -7,6 +7,8 @@
#include <string.h>
#include <string>
+using namespace std;
+
namespace LuaBind
{
OnRegisterClassHandler onRegisterNativeClass = NULL;
@@ -415,6 +417,34 @@ namespace LuaBind
lua_gettable(mState, idx);
}
+ bool State::GetGlobalField(const char* fullName)
+ {
+ if (fullName == NULL || strlen(fullName) == 0)
+ return false;
+ int top = GetTop();
+ lua_pushvalue(*this, LUA_GLOBALSINDEX);
+ string name = fullName;
+ while (name.size() > 0)
+ {
+ int dot = name.find('.');
+ dot = dot != string::npos ? dot : name.size();
+ string pkg = name.substr(0, dot);
+ if (dot < name.size())
+ name = name.substr(dot + 1, name.size() - dot - 1);
+ else
+ name = "";
+ lua_getfield(*this, -1, pkg.c_str());
+ if (lua_isnil(*this, -1))
+ {
+ lua_settop(*this, top);
+ return false;
+ }
+ }
+ lua_replace(*this, top + 1);
+ lua_settop(*this, top + 1);
+ return true;
+ }
+
std::string State::GetField(int idx, cc8* key, cc8* default_value)
{
std::string str;
diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h
index aaad952..e8ac42d 100644
--- a/Runtime/Lua/LuaBind/LuaBindState.h
+++ b/Runtime/Lua/LuaBind/LuaBindState.h
@@ -74,6 +74,8 @@ namespace LuaBind
//------------------------------------------------------------------------------//
+ bool GetGlobalField(const char* fullName);
+
void GetField(int idx, cc8* name);
void GetField(int idx, int key);
std::string GetField(int idx, cc8* key, cc8* value);
diff --git a/Runtime/Lua/LuaHelper.cpp b/Runtime/Lua/LuaHelper.cpp
index 71fe782..084d4f6 100644
--- a/Runtime/Lua/LuaHelper.cpp
+++ b/Runtime/Lua/LuaHelper.cpp
@@ -236,4 +236,32 @@ bool LuaHelper::GetLuaClass(LuaBind::State& state, const char* fullName)
lua_replace(state, top + 1);
lua_settop(state, top + 1);
return true;
+}
+
+bool LuaHelper::GetGlobalField(LuaBind::State& state, const char* fullName)
+{
+ if (fullName == NULL || strlen(fullName) == 0)
+ return false;
+ int top = state.GetTop();
+ lua_pushvalue(state, LUA_GLOBALSINDEX);
+ string name = fullName;
+ while (name.size() > 0)
+ {
+ int dot = name.find('.');
+ dot = dot != string::npos ? dot : name.size();
+ string pkg = name.substr(0, dot);
+ if (dot < name.size())
+ name = name.substr(dot + 1, name.size() - dot - 1);
+ else
+ name = "";
+ lua_getfield(state, -1, pkg.c_str());
+ if (lua_isnil(state, -1))
+ {
+ lua_settop(state, top);
+ return false;
+ }
+ }
+ lua_replace(state, top + 1);
+ lua_settop(state, top + 1);
+ return true;
} \ No newline at end of file
diff --git a/Runtime/Lua/LuaHelper.h b/Runtime/Lua/LuaHelper.h
index 79cab29..1c18620 100644
--- a/Runtime/Lua/LuaHelper.h
+++ b/Runtime/Lua/LuaHelper.h
@@ -15,5 +15,8 @@ public:
// 找到类table,并留在栈顶,如果返回false表示没有找到,栈顶无值
static bool GetLuaClass(LuaBind::State& state, const char* fullName);
+
+ // 找到全局表下的数据
+ static bool GetGlobalField(LuaBind::State& state, const char* fullName);
-}; \ No newline at end of file
+};
diff --git a/Runtime/Scripting/RuntimeScriptingManager.h b/Runtime/Scripting/RuntimeScriptingManager.h
new file mode 100644
index 0000000..b8db959
--- /dev/null
+++ b/Runtime/Scripting/RuntimeScriptingManager.h
@@ -0,0 +1,22 @@
+#pragma once
+#include "Runtime/Utilities/Singleton.h"
+#include "ScriptGlobals.h"
+#include "Runtime/Utilities/UtilMacros.h"
+
+class RuntimeScriptingManager : public Singleton<RuntimeScriptingManager >
+{
+public:
+ RuntimeScriptingManager();
+
+ GET(const ScriptGlobals&, Globals, m_Globals);
+
+private:
+ void FillGloabls();
+
+ ScriptGlobals m_Globals; // lua侧的全局方法
+
+};
+
+#define SCRIPT_GLOBAL RuntimeScriptingManager::Instance()->GetGlobals()
+
+
diff --git a/Runtime/Scripting/ScriptGlobals.h b/Runtime/Scripting/ScriptGlobals.h
new file mode 100644
index 0000000..af396bd
--- /dev/null
+++ b/Runtime/Scripting/ScriptGlobals.h
@@ -0,0 +1,10 @@
+#pragma once
+#include "Runtime/Lua/LuaHelper.h"
+
+#define DECL_LUA_FUNC(name) LuaBind::LuaFunction name
+
+// 全局方法和变量
+struct ScriptGlobals
+{
+ DECL_LUA_FUNC(setCurrentEvent);
+}; \ No newline at end of file
diff --git a/Runtime/Scripting/ScriptingManager.cpp b/Runtime/Scripting/ScriptingManager.cpp
new file mode 100644
index 0000000..5b26262
--- /dev/null
+++ b/Runtime/Scripting/ScriptingManager.cpp
@@ -0,0 +1,14 @@
+#include "RuntimeScriptingManager.h"
+
+RuntimeScriptingManager::RuntimeScriptingManager()
+{
+
+
+
+}
+
+void RuntimeScriptingManager::FillGloabls()
+{
+ m_Globals.setCurrentEvent = "GameLab.Events.Event.SetCurrentEvent";
+
+} \ No newline at end of file