summaryrefslogtreecommitdiff
path: root/Runtime/LuaBind/LuaBindState.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-18 02:12:30 +0800
committerchai <chaifix@163.com>2021-10-18 02:12:30 +0800
commit22e576b5aa065f3cb2ca67a951af5e68063419a2 (patch)
treed72c6c77e33990cc70952c58e9ca50637ba6c242 /Runtime/LuaBind/LuaBindState.cpp
parent7c8c68d79343d04be382334c15a73d079450857c (diff)
*scripting
Diffstat (limited to 'Runtime/LuaBind/LuaBindState.cpp')
-rw-r--r--Runtime/LuaBind/LuaBindState.cpp33
1 files changed, 32 insertions, 1 deletions
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 <string>
+
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;
}