From 22e576b5aa065f3cb2ca67a951af5e68063419a2 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 18 Oct 2021 02:12:30 +0800 Subject: *scripting --- Runtime/Graphics/OpenGL.cpp | 3 +++ Runtime/ImGUI/GUIButton.cpp | 0 Runtime/ImGUI/GUIButton.h | 6 ------ Runtime/ImGUI/GUILabel.cpp | 0 Runtime/ImGUI/GUILabel.h | 0 Runtime/LuaBind/LuaBindCFunctions.h | 21 +++++++++++++++++---- Runtime/LuaBind/LuaBindState.cpp | 33 ++++++++++++++++++++++++++++++++- Runtime/Scripting/GL.bind.cpp | 9 --------- Runtime/Scripting/GL/GL.bind.cpp | 9 +++++++++ 9 files changed, 61 insertions(+), 20 deletions(-) delete mode 100644 Runtime/ImGUI/GUIButton.cpp delete mode 100644 Runtime/ImGUI/GUIButton.h delete mode 100644 Runtime/ImGUI/GUILabel.cpp delete mode 100644 Runtime/ImGUI/GUILabel.h delete mode 100644 Runtime/Scripting/GL.bind.cpp create mode 100644 Runtime/Scripting/GL/GL.bind.cpp (limited to 'Runtime') diff --git a/Runtime/Graphics/OpenGL.cpp b/Runtime/Graphics/OpenGL.cpp index e69de29..e0dc8f1 100644 --- a/Runtime/Graphics/OpenGL.cpp +++ b/Runtime/Graphics/OpenGL.cpp @@ -0,0 +1,3 @@ +#include "OpenGL.h" + +#pragma comment(lib, "opengl32.lib") diff --git a/Runtime/ImGUI/GUIButton.cpp b/Runtime/ImGUI/GUIButton.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Runtime/ImGUI/GUIButton.h b/Runtime/ImGUI/GUIButton.h deleted file mode 100644 index fbcd0bb..0000000 --- a/Runtime/ImGUI/GUIButton.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef GUI_BUTTON_H -#define GUI_BUTTON_H - - - -#endif \ No newline at end of file diff --git a/Runtime/ImGUI/GUILabel.cpp b/Runtime/ImGUI/GUILabel.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Runtime/ImGUI/GUILabel.h b/Runtime/ImGUI/GUILabel.h deleted file mode 100644 index e69de29..0000000 diff --git a/Runtime/LuaBind/LuaBindCFunctions.h b/Runtime/LuaBind/LuaBindCFunctions.h index 25ccbc2..f0f07dd 100644 --- a/Runtime/LuaBind/LuaBindCFunctions.h +++ b/Runtime/LuaBind/LuaBindCFunctions.h @@ -10,16 +10,29 @@ namespace { - // // 获得第一个upvalue - // extern int luax_c_getupvalue(lua_State* L); - // // 调用此函数时会报错,upvalue(1)是错误信息 - // extern int luax_c_errfunc(lua_State* L); +#define luax_is(T, L, i) (lua_is##T(L, i)) +#define luax_isnumber(L, i) luax_is(number, L, i) + + inline int luax_isinteger(lua_State* L, int i) + { + if (!luax_isnumber(L, i)) + return 0; + return lua_tonumber(L, i) == lua_tointeger(L, i); + } + + inline int luax_isfloat(lua_State* L, int i) + { + if (!luax_isnumber(L, i)) + return 0; + return lua_tonumber(L, i) != lua_tointeger(L, i); + } + } #endif \ No newline at end of file diff --git a/Runtime/LuaBind/LuaBindState.cpp b/Runtime/LuaBind/LuaBindState.cpp index a9520a8..4ee87f4 100644 --- a/Runtime/LuaBind/LuaBindState.cpp +++ b/Runtime/LuaBind/LuaBindState.cpp @@ -4,6 +4,8 @@ #include "LuaBindClass.hpp" #include "LuaBindInternal.h" +#include + namespace LuaBind { @@ -40,6 +42,7 @@ namespace LuaBind void State::PushGlobalNamespace() { +#if false int top = GetTop(); lua_newtable(mState); // pseudo namespace table @@ -59,6 +62,9 @@ namespace LuaBind // stack: // -1 pseudo global namespace +#else + lua_pushvalue(mState, LUA_GLOBALSINDEX); +#endif } void State::PushNamespace(cc8* name) @@ -533,13 +539,38 @@ namespace LuaBind return value; } - + static std::string s_str; template <> cc8* State::GetValue < cc8* >(int idx, const cc8* value) { if (this->IsType(idx, LUA_TSTRING)) { return lua_tostring(this->mState, idx); } + + if (this->IsType(idx, LUA_TNUMBER)) { + if (luax_isinteger(mState, -1)) { + int num = lua_tointeger(this->mState, idx); + s_str = std::to_string(num); + cc8* str = s_str.c_str(); + return str; + } + else { + float num = lua_tonumber(this->mState, idx); + s_str = std::to_string(num); + cc8* str = s_str.c_str(); + return str; + } + } + + if (this->IsType(idx, LUA_TBOOLEAN)) { + bool b = lua_toboolean(this->mState, idx); + return b ? "true" : "false"; + } + + if (this->IsType(idx, LUA_TNIL)) { + return "NIL"; + } + return value; } diff --git a/Runtime/Scripting/GL.bind.cpp b/Runtime/Scripting/GL.bind.cpp deleted file mode 100644 index 57dba09..0000000 --- a/Runtime/Scripting/GL.bind.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Runtime/Graphics/OpenGL.h" -#include "Runtime/LuaBind/LuaBind.h" - -// GameLab.Engine.GL -void luaopen_GameLab_Engine_GL(lua_State* L) -{ - LUA_BIND_STATE(L); - -} diff --git a/Runtime/Scripting/GL/GL.bind.cpp b/Runtime/Scripting/GL/GL.bind.cpp new file mode 100644 index 0000000..57dba09 --- /dev/null +++ b/Runtime/Scripting/GL/GL.bind.cpp @@ -0,0 +1,9 @@ +#include "Runtime/Graphics/OpenGL.h" +#include "Runtime/LuaBind/LuaBind.h" + +// GameLab.Engine.GL +void luaopen_GameLab_Engine_GL(lua_State* L) +{ + LUA_BIND_STATE(L); + +} -- cgit v1.1-26-g67d0