aboutsummaryrefslogtreecommitdiff
path: root/src/lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/common/Proxy.h67
-rw-r--r--src/lua/common/Reference.hpp88
-rw-r--r--src/lua/common/common.h8
-rw-r--r--src/lua/common/error.h28
-rw-r--r--src/lua/common/je_lua_callback.cpp43
-rw-r--r--src/lua/common/je_lua_callback.h67
-rw-r--r--src/lua/common/je_lua_common.h10
-rw-r--r--src/lua/common/je_lua_constant.h (renamed from src/lua/common/constant.h)0
-rw-r--r--src/lua/common/je_lua_error.h28
-rw-r--r--src/lua/common/je_lua_function.cpp0
-rw-r--r--src/lua/common/je_lua_function.h6
-rw-r--r--src/lua/common/je_lua_port.h8
-rw-r--r--src/lua/common/je_lua_proxy.h72
-rw-r--r--src/lua/common/je_lua_reference.cpp31
-rw-r--r--src/lua/common/je_lua_reference.h54
-rw-r--r--src/lua/common/je_lua_shared.hpp151
-rw-r--r--src/lua/embed/boot.lua.h175
-rw-r--r--src/lua/embed/embed.h46
-rw-r--r--src/lua/embed/graphics.lua.h46
-rw-r--r--src/lua/embed/scripts/ai.lua.h26
-rw-r--r--src/lua/embed/scripts/boot.lua.h139
-rw-r--r--src/lua/embed/scripts/graphics.lua.h73
-rw-r--r--src/lua/embed/scripts/keyboard.lua.h (renamed from src/lua/embed/keyboard.lua.h)2
-rw-r--r--src/lua/embed/scripts/mouse.lua.h (renamed from src/lua/embed/mouse.lua.h)2
-rw-r--r--src/lua/embed/scripts/net.lua.h (renamed from src/lua/embed/net.lua.h)3
-rw-r--r--src/lua/embed/scripts/path.lua.h (renamed from src/lua/embed/path.lua.h)2
-rw-r--r--src/lua/jin.cpp94
-rw-r--r--src/lua/jin.h5
-rw-r--r--src/lua/libraries/luax/luax.h26
-rw-r--r--src/lua/main.cpp44
-rw-r--r--src/lua/modules/ai/je_lua_ai.cpp13
-rw-r--r--src/lua/modules/ai/je_lua_ai.h7
-rw-r--r--src/lua/modules/ai/je_lua_behavior_tree.cpp11
-rw-r--r--src/lua/modules/ai/je_lua_behavior_tree.h14
-rw-r--r--src/lua/modules/ai/je_lua_state_machine.cpp25
-rw-r--r--src/lua/modules/ai/je_lua_state_machine.h14
-rw-r--r--src/lua/modules/audio/audio.cpp123
-rw-r--r--src/lua/modules/audio/je_lua_audio.cpp135
-rw-r--r--src/lua/modules/audio/je_lua_audio.h6
-rw-r--r--src/lua/modules/audio/je_lua_source.cpp117
-rw-r--r--src/lua/modules/audio/je_lua_source.h16
-rw-r--r--src/lua/modules/audio/source.cpp116
-rw-r--r--src/lua/modules/bit/je_lua_bit.cpp (renamed from src/lua/modules/bit/bit.cpp)41
-rw-r--r--src/lua/modules/bit/je_lua_bit.h0
-rw-r--r--src/lua/modules/core/core.cpp46
-rw-r--r--src/lua/modules/core/je_lua_core.cpp46
-rw-r--r--src/lua/modules/core/je_lua_core.h0
-rw-r--r--src/lua/modules/event/je_lua_event.cpp (renamed from src/lua/modules/event/event.cpp)26
-rw-r--r--src/lua/modules/event/je_lua_event.h0
-rw-r--r--src/lua/modules/filesystem/je_lua_filesystem.cpp (renamed from src/lua/modules/filesystem/filesystem.cpp)41
-rw-r--r--src/lua/modules/filesystem/je_lua_filesystem.h0
-rw-r--r--src/lua/modules/graphics/bitmap.cpp113
-rw-r--r--src/lua/modules/graphics/canvas.cpp65
-rw-r--r--src/lua/modules/graphics/je_lua_bitmap.cpp114
-rw-r--r--src/lua/modules/graphics/je_lua_bitmap.h16
-rw-r--r--src/lua/modules/graphics/je_lua_canvas.cpp66
-rw-r--r--src/lua/modules/graphics/je_lua_canvas.h16
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp (renamed from src/lua/modules/graphics/graphics.cpp)561
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.h0
-rw-r--r--src/lua/modules/graphics/je_lua_page.cpp69
-rw-r--r--src/lua/modules/graphics/je_lua_page.h22
-rw-r--r--src/lua/modules/graphics/je_lua_particle_system.cpp11
-rw-r--r--src/lua/modules/graphics/je_lua_particle_system.h0
-rw-r--r--src/lua/modules/graphics/je_lua_shader.cpp137
-rw-r--r--src/lua/modules/graphics/je_lua_shader.h16
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.cpp262
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.h24
-rw-r--r--src/lua/modules/graphics/je_lua_spritesheet.cpp54
-rw-r--r--src/lua/modules/graphics/je_lua_spritesheet.h21
-rw-r--r--src/lua/modules/graphics/je_lua_text.cpp32
-rw-r--r--src/lua/modules/graphics/je_lua_text.h16
-rw-r--r--src/lua/modules/graphics/je_lua_texture.cpp66
-rw-r--r--src/lua/modules/graphics/je_lua_texture.h16
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.cpp66
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.h16
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.cpp66
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.h16
-rw-r--r--src/lua/modules/graphics/je_lua_ttf_data.cpp52
-rw-r--r--src/lua/modules/graphics/je_lua_ttf_data.h21
-rw-r--r--src/lua/modules/graphics/page.cpp73
-rw-r--r--src/lua/modules/graphics/shader.cpp135
-rw-r--r--src/lua/modules/graphics/text.cpp32
-rw-r--r--src/lua/modules/graphics/texture.cpp65
-rw-r--r--src/lua/modules/graphics/texture_font.cpp67
-rw-r--r--src/lua/modules/graphics/ttf.cpp73
-rw-r--r--src/lua/modules/graphics/ttfData.cpp51
-rw-r--r--src/lua/modules/joypad/je_lua_joypad.cpp (renamed from src/lua/modules/joypad/joypad.cpp)12
-rw-r--r--src/lua/modules/joypad/je_lua_joypad.h0
-rw-r--r--src/lua/modules/keyboard/je_lua_keyboard.cpp (renamed from src/lua/modules/keyboard/keyboard.cpp)3
-rw-r--r--src/lua/modules/keyboard/je_lua_keyboard.h0
-rw-r--r--src/lua/modules/math/je_lua_math.cpp (renamed from src/lua/modules/math/math.cpp)14
-rw-r--r--src/lua/modules/math/je_lua_math.h0
-rw-r--r--src/lua/modules/mouse/je_lua_mouse.cpp (renamed from src/lua/modules/mouse/mouse.cpp)22
-rw-r--r--src/lua/modules/mouse/je_lua_mouse.h0
-rw-r--r--src/lua/modules/net/Buffer.cpp142
-rw-r--r--src/lua/modules/net/je_lua_buffer.cpp137
-rw-r--r--src/lua/modules/net/je_lua_buffer.h (renamed from src/lua/modules/net/Buffer.h)7
-rw-r--r--src/lua/modules/net/je_lua_net.cpp (renamed from src/lua/modules/net/net.cpp)42
-rw-r--r--src/lua/modules/net/je_lua_net.h0
-rw-r--r--src/lua/modules/net/je_lua_socket.cpp129
-rw-r--r--src/lua/modules/net/je_lua_socket.h16
-rw-r--r--src/lua/modules/net/socket.cpp129
-rw-r--r--src/lua/modules/thread/Thread.cpp252
-rw-r--r--src/lua/modules/thread/Thread.h94
-rw-r--r--src/lua/modules/thread/je_lua_thread.cpp248
-rw-r--r--src/lua/modules/thread/je_lua_thread.h93
-rw-r--r--src/lua/modules/time/je_lua_time.cpp71
-rw-r--r--src/lua/modules/time/je_lua_time.h0
-rw-r--r--src/lua/modules/time/je_lua_timer.cpp146
-rw-r--r--src/lua/modules/time/je_lua_timer.h20
-rw-r--r--src/lua/modules/time/time.cpp38
-rw-r--r--src/lua/modules/types.h25
-rw-r--r--src/lua/resources/font.ttfbin84564 -> 0 bytes
-rw-r--r--src/lua/resources/font.ttf.h714
114 files changed, 4069 insertions, 2856 deletions
diff --git a/src/lua/common/Proxy.h b/src/lua/common/Proxy.h
deleted file mode 100644
index 5ebb5b2..0000000
--- a/src/lua/common/Proxy.h
+++ /dev/null
@@ -1,67 +0,0 @@
-#ifndef __JIN_COMMON_PROXY_H
-#define __JIN_COMMON_PROXY_H
-
-#include "Reference.hpp"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- class Proxy
- {
- public:
- void bind(RefBase* ref)
- {
- if (ref == nullptr)
- return;
- reference = ref;
- }
-
- void release()
- {
- if (reference != nullptr)
- {
- reference->release();
- reference = nullptr;
- }
- }
-
- void retain()
- {
- if (reference != nullptr)
- reference->retain();
- }
-
- void setUserdata(void* data)
- {
- if (reference != nullptr)
- reference->setUserdata(data);
- }
-
- template<class T>
- Ref<T>& getRef()
- {
- return *(Ref<T>*) reference;
- }
-
- template<class T>
- T* getObject()
- {
- Ref<T>& ref = getRef<T>();
- return ref.getObject();
- }
-
- const char* getObjectType()
- {
- return reference->type;
- }
-
- RefBase* reference;
-
- };
-
- } // namespace Lua
-} // namespace JinEngine
-
-#endif // __JIN_COMMON_PROXY_H \ No newline at end of file
diff --git a/src/lua/common/Reference.hpp b/src/lua/common/Reference.hpp
deleted file mode 100644
index ba918bb..0000000
--- a/src/lua/common/Reference.hpp
+++ /dev/null
@@ -1,88 +0,0 @@
-#ifndef __JIN_COMMON_REFERENCE_H
-#define __JIN_COMMON_REFERENCE_H
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- /*abstract*/class RefBase
- {
- public:
- void retain()
- {
- ++count;
- }
-
- void release()
- {
- if (--count <= 0)
- delete this;
- }
-
- // object type string
- const char* const type;
-
- void setUserdata(void* data)
- {
- userdata = data;
- }
-
- void* getUserdata()
- {
- return userdata;
- }
-
- protected:
- RefBase(void* obj, const char* t)
- : count(1)
- , object(obj)
- , type(t)
- {
- }
-
- RefBase(const RefBase&);
-
- virtual ~RefBase()
- {
- }
-
- void* object;
- int count;
- void* userdata;
- };
-
- template<class T>
- class Ref : public RefBase
- {
- public:
- Ref(T* obj, const char* type)
- : RefBase(obj, type)
- {
- }
-
- ~Ref()
- {
- T* obj = static_cast<T*>(object);
- delete obj;
- }
-
- T* operator->()
- {
- return (T*)object;
- }
-
- T* getObject()
- {
- return (T*)object;
- }
-
- private:
- Ref(const Ref<T>& ref);
-
- };
-
- }
-}
-
-#endif \ No newline at end of file
diff --git a/src/lua/common/common.h b/src/lua/common/common.h
deleted file mode 100644
index 0ee72cc..0000000
--- a/src/lua/common/common.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef __JIN_M_TYPES_H
-#define __JIN_M_TYPES_H
-
-#include "Proxy.h"
-#include "Reference.hpp"
-#include "error.h"
-
-#endif \ No newline at end of file
diff --git a/src/lua/common/error.h b/src/lua/common/error.h
deleted file mode 100644
index c254486..0000000
--- a/src/lua/common/error.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef __JIN_ERROR_H
-#define __JIN_ERROR_H
-#include "../../luax.h"
-#include "../jin.h"
-#include <string.h>
-
-namespace JinEngine
-{
-namespace Lua
-{
-
- static const int FORMAT_MSG_BUFFER_SIZE = 2048;
-
- inline void error(lua_State* L, const char* fmt, ...)
- {
- char err[FORMAT_MSG_BUFFER_SIZE + 1] = { 0 };
- va_list args;
- va_start(args, fmt);
- vsnprintf(err + strlen(err), FORMAT_MSG_BUFFER_SIZE, fmt, args);
- va_end(args);
- luax_getglobal(L, MODULE_NAME);
- luax_setfieldstring(L, "error", err);
- }
-
-}
-}
-
-#endif \ No newline at end of file
diff --git a/src/lua/common/je_lua_callback.cpp b/src/lua/common/je_lua_callback.cpp
new file mode 100644
index 0000000..392f919
--- /dev/null
+++ b/src/lua/common/je_lua_callback.cpp
@@ -0,0 +1,43 @@
+#include "je_lua_callback.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ LuaCallback::LuaCallback(lua_State* L)
+ : mLuaFunc(nullptr)
+ , mParams(0)
+ , mL(L)
+ {
+ }
+
+ LuaCallback::~LuaCallback()
+ {
+ delete mLuaFunc;
+ for (auto p : mParams)
+ delete p;
+ }
+
+ void LuaCallback::setFunc(int i)
+ {
+ if (mLuaFunc != nullptr)
+ delete mLuaFunc;
+ mLuaFunc = new LuaRef(mL, i);
+ }
+
+ void LuaCallback::pushParam(int i)
+ {
+ mParams.push_back(new LuaRef(mL, i));
+ }
+
+ void LuaCallback::call()
+ {
+ mLuaFunc->push();
+ for (auto p : mParams)
+ p->push();
+ luax_call(mL, mParams.size(), 0);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/common/je_lua_callback.h b/src/lua/common/je_lua_callback.h
new file mode 100644
index 0000000..f3301fc
--- /dev/null
+++ b/src/lua/common/je_lua_callback.h
@@ -0,0 +1,67 @@
+#ifndef __JIN_COMMON_FUNCTION_H
+#define __JIN_COMMON_FUNCTION_H
+
+#include <vector>
+
+#include "libjin/jin.h"
+#include "../luax.h"
+#include "je_lua_reference.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ ///
+ ///
+ ///
+ class LuaCallback
+ {
+ public:
+ ///
+ ///
+ ///
+ LuaCallback(lua_State* L);
+
+ ///
+ ///
+ ///
+ ~LuaCallback();
+
+ ///
+ ///
+ ///
+ void setFunc(int i);
+
+ ///
+ ///
+ ///
+ void pushParam(int i);
+
+ ///
+ ///
+ ///
+ void call();
+
+ private:
+ ///
+ ///
+ ///
+ LuaRef* mLuaFunc;
+
+ ///
+ ///
+ ///
+ std::vector<LuaRef*> mParams;
+
+ ///
+ ///
+ ///
+ lua_State* const mL;
+
+ };
+
+ } // namespace Lua
+} // namespace JinEngine
+
+#endif // __JIN_COMMON_REFERENCE_H \ No newline at end of file
diff --git a/src/lua/common/je_lua_common.h b/src/lua/common/je_lua_common.h
new file mode 100644
index 0000000..5b217a2
--- /dev/null
+++ b/src/lua/common/je_lua_common.h
@@ -0,0 +1,10 @@
+#ifndef __JIN_M_TYPES_H
+#define __JIN_M_TYPES_H
+
+#include "je_lua_port.h"
+#include "je_lua_proxy.h"
+#include "je_lua_shared.hpp"
+#include "je_lua_error.h"
+#include "je_lua_reference.h"
+
+#endif \ No newline at end of file
diff --git a/src/lua/common/constant.h b/src/lua/common/je_lua_constant.h
index 6f70f09..6f70f09 100644
--- a/src/lua/common/constant.h
+++ b/src/lua/common/je_lua_constant.h
diff --git a/src/lua/common/je_lua_error.h b/src/lua/common/je_lua_error.h
new file mode 100644
index 0000000..3f7e76f
--- /dev/null
+++ b/src/lua/common/je_lua_error.h
@@ -0,0 +1,28 @@
+#ifndef __JIN_ERROR_H
+#define __JIN_ERROR_H
+#include "../luax.h"
+#include <string.h>
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ static const int FORMAT_MSG_BUFFER_SIZE = 2048;
+
+ inline void error(lua_State* L, const char* fmt, ...)
+ {
+ char err[FORMAT_MSG_BUFFER_SIZE + 1] = { 0 };
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(err + strlen(err), FORMAT_MSG_BUFFER_SIZE, fmt, args);
+ va_end(args);
+ //luax_getglobal(L, "jin");
+ //luax_setfieldstring(L, "error", err);
+ luax_error(L, err);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/lua/common/je_lua_function.cpp b/src/lua/common/je_lua_function.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/common/je_lua_function.cpp
diff --git a/src/lua/common/je_lua_function.h b/src/lua/common/je_lua_function.h
new file mode 100644
index 0000000..49c1b31
--- /dev/null
+++ b/src/lua/common/je_lua_function.h
@@ -0,0 +1,6 @@
+#ifndef __JE_LUA_FUNCTION_H__
+#define __JE_LUA_FUNCTION_H__
+
+
+
+#endif \ No newline at end of file
diff --git a/src/lua/common/je_lua_port.h b/src/lua/common/je_lua_port.h
new file mode 100644
index 0000000..8e99ca4
--- /dev/null
+++ b/src/lua/common/je_lua_port.h
@@ -0,0 +1,8 @@
+#ifndef __JE_LUA_PORT_H
+#define __JE_LUA_PORT_H
+
+#define LUA_PORT extern
+#define LUA_IMPLEMENT static
+#define LUA_EXPORT
+
+#endif \ No newline at end of file
diff --git a/src/lua/common/je_lua_proxy.h b/src/lua/common/je_lua_proxy.h
new file mode 100644
index 0000000..ca4a56a
--- /dev/null
+++ b/src/lua/common/je_lua_proxy.h
@@ -0,0 +1,72 @@
+#ifndef __JIN_COMMON_PROXY_H
+#define __JIN_COMMON_PROXY_H
+
+#include "../luax.h"
+
+#include "je_lua_shared.hpp"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ class Proxy
+ {
+ public:
+ void bind(SharedBase* s)
+ {
+ if (s == nullptr)
+ return;
+ shared = s;
+ shared->retain();
+ }
+
+ void release()
+ {
+ if (shared != nullptr)
+ {
+ shared->release();
+ shared = nullptr;
+ }
+ }
+/*
+ void retain()
+ {
+ if (shared != nullptr)
+ shared->retain();
+ }
+*/
+ template<class T>
+ Shared<T>& getShared()
+ {
+ return *(Shared<T>*)shared;
+ }
+
+ ///
+ /// For convenience.
+ ///
+ template<class T>
+ T* getObject()
+ {
+ Shared<T>& shared = getShared<T>();
+ return shared.getObject();
+ }
+
+ const char* getObjectType()
+ {
+ return shared->type;
+ }
+
+ SharedBase* shared;
+
+ };
+
+ inline Proxy* luax_newinstance(lua_State* L, const char* type)
+ {
+ return static_cast<Proxy*>(luax_newinstance(L, type, sizeof(Proxy)));
+ }
+
+ } // namespace Lua
+} // namespace JinEngine
+
+#endif // __JIN_COMMON_PROXY_H \ No newline at end of file
diff --git a/src/lua/common/je_lua_reference.cpp b/src/lua/common/je_lua_reference.cpp
new file mode 100644
index 0000000..90223de
--- /dev/null
+++ b/src/lua/common/je_lua_reference.cpp
@@ -0,0 +1,31 @@
+#include "je_lua_reference.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ LuaRef::LuaRef(lua_State* L, int i)
+ : mL(L)
+ {
+ luax_pushvalue(mL, i);
+ mIndex = luax_ref(mL, LUA_REGISTRYINDEX);
+ }
+
+ LuaRef::~LuaRef()
+ {
+ unref();
+ }
+
+ void LuaRef::unref()
+ {
+ luax_unref(mL, LUA_REGISTRYINDEX, mIndex);
+ }
+
+ void LuaRef::push()
+ {
+ luax_rawgeti(mL, LUA_REGISTRYINDEX, mIndex);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/common/je_lua_reference.h b/src/lua/common/je_lua_reference.h
new file mode 100644
index 0000000..f338762
--- /dev/null
+++ b/src/lua/common/je_lua_reference.h
@@ -0,0 +1,54 @@
+#ifndef __JIN_COMMON_REFERENCE_H
+#define __JIN_COMMON_REFERENCE_H
+
+#include "../luax.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ ///
+ /// This class wraps the reference functionality built into Lua, which allows C++ code to refer to Lua
+ /// variables.
+ ///
+ class LuaRef
+ {
+ public:
+ ///
+ ///
+ ///
+ LuaRef(lua_State* L, int i);
+
+ ///
+ ///
+ ///
+ ~LuaRef();
+
+ ///
+ ///
+ ///
+ void unref();
+
+ ///
+ /// Push value onto the stack.
+ ///
+ void push();
+
+ private:
+ ///
+ ///
+ ///
+ lua_State* const mL;
+
+ ///
+ ///
+ ///
+ int mIndex;
+
+ };
+
+ } // namespace Lua
+} // namespace JinEngine
+
+#endif // __JIN_COMMON_REFERENCE_H \ No newline at end of file
diff --git a/src/lua/common/je_lua_shared.hpp b/src/lua/common/je_lua_shared.hpp
new file mode 100644
index 0000000..91705d1
--- /dev/null
+++ b/src/lua/common/je_lua_shared.hpp
@@ -0,0 +1,151 @@
+#ifndef __JIN_COMMON_SHARED_H__
+#define __JIN_COMMON_SHARED_H__
+
+#include <map>
+#include <vector>
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ class SharedBase
+ {
+ public:
+ void retain()
+ {
+ ++mCount;
+ }
+
+ void release()
+ {
+ if (--mCount <= 0)
+ delete this;
+ }
+
+ // Object type.
+ const char* const type;
+
+ void setDependency(int key, SharedBase* shared)
+ {
+ removeDependency(key);
+ shared->retain();
+ mDependencies.insert(std::pair<int, SharedBase*>(key, shared));
+ }
+
+ void removeDependency(int key)
+ {
+ if (!isDependOn(key))
+ return;
+ DepMap::iterator it = mDependencies.find(key);
+ it->second->release();
+ mDependencies.erase(it);
+ }
+
+ void removeDependency(SharedBase* dep)
+ {
+ for (DepMap::iterator it = mDependencies.begin(); it != mDependencies.end();)
+ {
+ if (it->second == dep)
+ {
+ it->second->release();
+ mDependencies.erase(it);
+ }
+ else
+ ++it;
+ }
+ }
+
+ bool isDependOn(int key)
+ {
+ return mDependencies.find(key) != mDependencies.end();
+ }
+
+ bool isDependOn(SharedBase* shared)
+ {
+ for (std::pair<int, SharedBase*> dep : mDependencies)
+ {
+ if (dep.second == shared)
+ return true;
+ }
+ return false;
+ }
+
+ void clearDependencies()
+ {
+ for (std::pair<int, SharedBase*> dep : mDependencies)
+ dep.second->release();
+ mDependencies.clear();
+ }
+
+ SharedBase* getDependency(int key)
+ {
+ if (!isDependOn(key))
+ return nullptr;
+ return mDependencies.find(key)->second;
+ }
+
+ bool isType(const char* t)
+ {
+ return strcmp(type, t) == 0;
+ }
+
+ protected:
+
+ using DepMap = std::map<int, SharedBase*>;
+
+ SharedBase(void* obj, const char* t)
+ : mCount(0)
+ , mObject(obj)
+ , type(t)
+ {
+ }
+
+ SharedBase(const SharedBase&);
+
+ virtual ~SharedBase()
+ {
+ clearDependencies();
+ }
+
+ void* mObject;
+ int mCount;
+ DepMap mDependencies;
+ };
+
+ template<class T>
+ class Shared : public SharedBase
+ {
+ public:
+ Shared(T* obj, const char* type)
+ : SharedBase(obj, type)
+ {
+ }
+
+ T* operator->()
+ {
+ return static_cast<T*>(mObject);
+ }
+
+ T* getObject()
+ {
+ return static_cast<T*>(mObject);
+ }
+
+ private:
+ // Disable copy constructor.
+ Shared(const Shared<T>& shared);
+
+ // Make shared only be able created with new.
+ ~Shared()
+ {
+ T* obj = static_cast<T*>(mObject);
+ delete obj;
+ }
+
+ };
+
+ } // namespace Lua
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/boot.lua.h
deleted file mode 100644
index 99e657b..0000000
--- a/src/lua/embed/boot.lua.h
+++ /dev/null
@@ -1,175 +0,0 @@
-/* boot.lua */
-static const char* boot_lua = R"(
-jin.args[2] = jin.args[2] or '.'
-jin.filesystem.init()
-jin.filesystem.mount(jin.args[2])
-
--------------------------------------------------------------------------
--- Config game
--------------------------------------------------------------------------
-
-jin.config = {}
-if jin.filesystem.exist("config.lua") then
- jin.config = require "config"
-end
-jin.config.width = jin.config.width or 576
-jin.config.height = jin.config.height or 448
-jin.config.vsync = jin.config.vsync or true
-jin.config.title = jin.config.title or ("jin v" .. jin.version)
-jin.config.resizable = jin.config.resizable or false
-jin.config.fullscreen = jin.config.fullscreen or false
-jin.config.fps = jin.config.fps or 60
-
--------------------------------------------------------------------------
--- Initialize sub systems
--------------------------------------------------------------------------
-
-jin.graphics.init(jin.config)
-jin.audio.init()
--- TODO: ϵͳģ
-
--------------------------------------------------------------------------
--- Default game loop
--------------------------------------------------------------------------
-
-local function call(func, ...)
- if func then
- return func(...)
- end
-end
-
-function jin.core.run()
- call(jin.core.onLoad)
- jin.graphics.reset()
- local dt = 0
- local previous = jin.time.second()
- local current = previous
- while jin.core.running() do
- for _, e in pairs(jin.event.poll()) do
- if e.type == "KeyDown" then
- jin.keyboard.set(e.key, true)
- elseif e.type == "KeyUp" then
- jin.keyboard.set(e.key, false)
- end
- call(jin.core.onEvent, e)
- end
- previous = current
- current = jin.time.second()
- dt = current - previous
- call(jin.core.onUpdate, dt)
- jin.graphics.clear()
- call(jin.core.onDraw)
- jin.graphics.present()
- -- Sleep 1 ms
- jin.time.sleep(0.001)
- end
-end
-
--------------------------------------------------------------------------
--- No game handler
--------------------------------------------------------------------------
-
-jin.core.setHandler = function(handler)
- if handler == nil then
- return
- end
- jin.core.onLoad = handler.onLoad
- jin.core.onEvent = handler.onEvent
- jin.core.onUpdate = handler.onUpdate
- jin.core.onDraw = handler.onDraw
-end
-
--- TODO: Ĭͼbase64
-jin.nogame = {
- cs = 64,
- sw = jin.graphics.getWidth(),
- sh = jin.graphics.getHeight(),
- cw = 0,
- ch = 0,
- ww = 6,
- ww2 = 6*2,
- speed = 4,
- t = 0,
- onLoad = function()
- local nogame = jin.nogame
- nogame.cw = nogame.sw / nogame.cs
- nogame.ch = nogame.sh / nogame.cs
- nogame.t = nogame.ww - 1
- end,
- onEvent = function(e)
- if e.type == 'Quit' then
- jin.core.stop()
- end
- end,
- onUpdate = function(dt)
- print(dt)
- local nogame = jin.nogame
- nogame.t = nogame.t + dt * nogame.speed
- if nogame.t > nogame.ww2 then
- nogame.t = nogame.t - nogame.ww2
- end
- end,
- circle = function(x, y, r)
- local nogame = jin.nogame
- if r % nogame.ww2 > nogame.ww then
- return
- end
- r = math.sin((r/nogame.ww)*math.pi)*nogame.cs/2
- local fact = (x + y) / nogame.ch * nogame.cw
- jin.graphics.setColor(
- 155 + 100 * math.sin(fact),
- 155 + 100 * math.cos(fact),
- 155 + 100 * math.sin(fact * fact),
- 255
- )
- jin.graphics.circle("fill", x*nogame.cs + nogame.cs/2, y*nogame.cs + nogame.cs/2, r)
- end,
- onDraw = function()
- local nogame = jin.nogame
- for y = 0, nogame.ch - 1 do
- for x = 0, nogame.cw - 1 do
- nogame.circle(x, y, nogame.t+x+y)
- end
- end
- end
-}
-
--------------------------------------------------------------------------
--- Boot jin
--------------------------------------------------------------------------
-
-local function onError(msg)
- jin.graphics.reset()
- jin.graphics.setClearColor(100, 100, 100, 255)
- jin.graphics.clear()
- jin.graphics.print("Error:\n" .. msg .. "\n" .. debug.traceback(), 5, 5)
- jin.graphics.present()
- while jin.core.running() do
- for _, e in pairs(jin.event.poll()) do
- if e.type == "Quit" then
- jin.core.stop()
- end
- end
- jin.time.sleep(0.001)
- end
- jin.core.quit()
-end
-
-local function boot()
- if jin.filesystem.exist("main.lua") then
- -- Require main game script
- xpcall(function() require"main" end, onError)
- xpcall(function() jin.core.run() end, onError)
- else
- -- No game
- jin.core.setHandler(jin.nogame)
- jin.core.run()
- end
- jin.graphics.destroy()
- jin.audio.destroy()
- jin.core.quit()
-end
-
-xpcall(boot, onError)
-
-)"; \ No newline at end of file
diff --git a/src/lua/embed/embed.h b/src/lua/embed/embed.h
index 18373c8..054672c 100644
--- a/src/lua/embed/embed.h
+++ b/src/lua/embed/embed.h
@@ -4,30 +4,26 @@
namespace JinEngine
{
-namespace embed
-{
+ namespace Embed
+ {
-#define embed(L, script, name)\
- if(luax_loadbuffer(L, script, strlen(script), name) == 0)\
- lua_call(L, 0, 0);
+ #define embed(L, script, name)\
+ if(luax_loadbuffer(L, script, strlen(script), name) == 0)\
+ lua_call(L, 0, 0);
- /**
- * embed structure.
- */
- struct jin_Embed
- {
- const char* file, *source;
- };
+ // Embed structure.
+ struct jin_Embed
+ {
+ const char* file, *source;
+ };
- static void boot(lua_State* L)
- {
- // embed scripts
- #include "graphics.lua.h"
- #include "keyboard.lua.h"
- #include "mouse.lua.h"
- #include "boot.lua.h"
+ // Embed scripts.
+ #include "scripts/graphics.lua.h"
+ #include "scripts/keyboard.lua.h"
+ #include "scripts/mouse.lua.h"
+ #include "scripts/boot.lua.h"
- // in order
+ // In order.
const jin_Embed scripts[] = {
{ "graphics.lua", graphics_lua },
{ "keyboard.lua", keyboard_lua },
@@ -36,11 +32,13 @@ namespace embed
{ 0, 0 }
};
- for (int i = 0; scripts[i].file; ++i)
- embed(L, scripts[i].source, scripts[i].file);
- }
+ static void boot(lua_State* L)
+ {
+ for (int i = 0; scripts[i].file; ++i)
+ embed(L, scripts[i].source, scripts[i].file);
+ }
-} // embed
+ } // namespace Embed
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/lua/embed/graphics.lua.h b/src/lua/embed/graphics.lua.h
deleted file mode 100644
index 5fa5dad..0000000
--- a/src/lua/embed/graphics.lua.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* graphics.lua */
-static const char* graphics_lua = R"(
-jin.graphics = jin.graphics or {}
-
-local default_shader = nil
-local default_shader_source = [[
-#VERTEX_SHADER
-
-Vertex vert(Vertex v)
-{
- return v;
-}
-
-#END_VERTEX_SHADER
-
-#FRAGMENT_SHADER
-
-Color frag(Color col, Texture tex, Vertex v)
-{
- return col * texel(tex, v.uv);
-}
-
-#END_FRAGMENT_SHADER
-]]
-
-local _init = jin.graphics.init
-
-jin.graphics.init = function(setting)
- _init(setting);
- default_shader = jin.graphics.newShader(default_shader_source)
- jin.graphics.useShader(default_shader)
-end
-
-jin.graphics.unuseShader = function()
- jin.graphics.useShader(default_shader)
-end
-
--- Reset all attributes to default value.
-jin.graphics.reset = function()
- jin.graphics.setColor(255, 255, 255, 255)
- jin.graphics.setClearColor(0, 0, 0, 255)
- jin.graphics.clear()
- jin.graphics.unsetFont()
-end
-
-)";
diff --git a/src/lua/embed/scripts/ai.lua.h b/src/lua/embed/scripts/ai.lua.h
new file mode 100644
index 0000000..a69da84
--- /dev/null
+++ b/src/lua/embed/scripts/ai.lua.h
@@ -0,0 +1,26 @@
+/* graphics.lua */
+static const char* ai_lua = R"(
+jin.ai = jin.ai or {}
+
+local ja = jin.ai
+
+ja.StateMachineType = {
+ STEPWISE = 1,
+ ITERATIVE = 2,
+}
+
+
+
+)";
+
+
+//local sp = jin.graphics.newSprite()
+//local sm = jin.ai.newStateMachine(jin.StateMachineMode.STEPWISE, sp)
+//sm:addState("run")
+//sm:addEnterCallback("run", function(spr)
+// spr:setRun()
+//end)
+//
+//function jin.core.onUpdate(dt)
+// sm:update()
+//end
diff --git a/src/lua/embed/scripts/boot.lua.h b/src/lua/embed/scripts/boot.lua.h
new file mode 100644
index 0000000..af81c16
--- /dev/null
+++ b/src/lua/embed/scripts/boot.lua.h
@@ -0,0 +1,139 @@
+/* boot.lua */
+static const char* boot_lua = R"(
+local cwd = jin.args['cwd'] or '.'
+jin.filesystem.init()
+jin.filesystem.mount(cwd)
+
+-------------------------------------------------------------------------
+-- Config game
+-------------------------------------------------------------------------
+
+jin.config = {}
+if jin.filesystem.exist("config.lua") then
+ xpcall(function()jin.config = require "config" end, function()end)
+end
+jin.config.width = jin.config.width or 580
+jin.config.height = jin.config.height or 450
+jin.config.vsync = jin.config.vsync or true
+jin.config.title = jin.config.title or ("jin v" .. jin.version)
+jin.config.resizable = jin.config.resizable or false
+jin.config.fullscreen = jin.config.fullscreen or false
+jin.config.fps = jin.config.fps or 60
+jin.config.icon = jin.config.icon or ""
+
+-------------------------------------------------------------------------
+-- Default game loop
+-------------------------------------------------------------------------
+
+local function call(func, ...)
+ if func then
+ return func(...)
+ end
+end
+
+local step = jin.time.step
+jin.time.step = nil
+
+function jin.core.run()
+ jin.graphics.reset()
+ call(jin.core.onLoad)
+ local dt = 0
+ while jin.core.running() do
+ for _, e in pairs(jin.event.poll()) do
+ if e.type == "KeyDown" then
+ jin.keyboard.set(e.key, true)
+ elseif e.type == "KeyUp" then
+ jin.keyboard.set(e.key, false)
+ end
+ call(jin.core.onEvent, e)
+ end
+ step()
+ dt = jin.time.getDelta()
+ call(jin.core.onUpdate)
+ jin.graphics.clear()
+ call(jin.core.onDraw)
+ jin.graphics.present()
+ jin.time.sleep(0.001)
+ end
+end
+
+-------------------------------------------------------------------------
+-- Boot game
+-------------------------------------------------------------------------
+
+-- Display error message.
+local function onError(msg)
+ jin.audio.destroy()
+ jin.graphics.showWindow()
+ local err = "Error:\n" .. msg .. "\n" .. debug.traceback()
+ jin.graphics.reset()
+ jin.graphics.setClearColor(100, 100, 100, 255)
+ jin.graphics.clear()
+ jin.graphics.print(err, 5, 5)
+ jin.graphics.present()
+ while jin.core.running() do
+ for _, e in pairs(jin.event.poll()) do
+ if e.type == "Quit" then
+ jin.core.stop()
+ end
+ end
+ jin.time.sleep(0.001)
+ end
+end
+
+-- No game screen.
+local function noGame()
+ jin.graphics.showWindow()
+ jin.graphics.reset()
+ jin.graphics.setClearColor(100, 100, 100, 255)
+ jin.graphics.clear()
+ jin.graphics.print("No Game", 5, 5)
+ jin.graphics.present()
+ while jin.core.running() do
+ for _, e in pairs(jin.event.poll()) do
+ if e.type == "Quit" then
+ jin.core.stop()
+ end
+ end
+ jin.time.sleep(0.001)
+ end
+end
+
+local function boot()
+ if jin.filesystem.exist("main.lua") then
+ call(function()
+ require"main"
+ jin.core.run()
+ end)
+ else
+ noGame()
+ end
+end
+
+-------------------------------------------------------------------------
+-- Initialize sub systems
+-------------------------------------------------------------------------
+
+jin.audio.init()
+jin.graphics.init(jin.config)
+
+-------------------------------------------------------------------------
+-- Boot game
+-------------------------------------------------------------------------
+
+xpcall(boot, onError)
+
+-------------------------------------------------------------------------
+-- Destroy sub-systems
+-------------------------------------------------------------------------
+
+jin.graphics.destroy()
+jin.audio.destroy()
+
+-------------------------------------------------------------------------
+-- Quit game
+-------------------------------------------------------------------------
+
+jin.core.quit()
+
+)"; \ No newline at end of file
diff --git a/src/lua/embed/scripts/graphics.lua.h b/src/lua/embed/scripts/graphics.lua.h
new file mode 100644
index 0000000..e1079b9
--- /dev/null
+++ b/src/lua/embed/scripts/graphics.lua.h
@@ -0,0 +1,73 @@
+/* graphics.lua */
+static const char* graphics_lua = R"(
+jin.graphics = jin.graphics or {}
+
+local jg = jin.graphics
+
+jg.RenderMode = {
+ FILL = 1,
+ LINE = 2,
+}
+
+jg.SpriteOrigin = {
+ TOPLEFT = 0,
+ TOPCENTER = 1,
+ TOPRIGHT = 2,
+ MIDDLELEFT = 3,
+ MIDDLECENTER = 4,
+ MIDDLERIGHT = 5,
+ BOTTOMLEFT = 6,
+ BOTTOMCENTER = 7,
+ BOTTOMRIGHT = 8
+}
+
+local default_shader = nil
+local default_shader_source = [[
+#VERTEX_SHADER
+
+Vertex vert(Vertex v)
+{
+ return v;
+}
+
+#END_VERTEX_SHADER
+
+#FRAGMENT_SHADER
+
+Color frag(Color col, Texture tex, Vertex v)
+{
+ return col * texel(tex, v.uv);
+}
+
+#END_FRAGMENT_SHADER
+]]
+
+local _init = jg.init
+local initialized = false
+
+jg.init = function(setting)
+ if initialized then
+ return initialized
+ end
+ initialized = _init(setting)
+ if initialized then
+ default_shader = jg.newShader(default_shader_source)
+ jg.useShader(default_shader)
+ end
+ return initialized
+end
+
+jg.unuseShader = function()
+ jg.useShader(default_shader)
+end
+
+-- Reset all attributes to default value.
+jg.reset = function()
+ jg.setColor(255, 255, 255, 255)
+ jg.setClearColor(0, 0, 0, 255)
+ jg.clear()
+ jg.unsetFont()
+ jg.unuseShader()
+end
+
+)"; \ No newline at end of file
diff --git a/src/lua/embed/keyboard.lua.h b/src/lua/embed/scripts/keyboard.lua.h
index ee8428f..e989928 100644
--- a/src/lua/embed/keyboard.lua.h
+++ b/src/lua/embed/scripts/keyboard.lua.h
@@ -2,6 +2,8 @@
static const char* keyboard_lua = R"(
jin.keyboard = jin.keyboard or {}
+local jk = jin.keyboard
+
local keys = {}
function jin.keyboard.isPressed(k)
diff --git a/src/lua/embed/mouse.lua.h b/src/lua/embed/scripts/mouse.lua.h
index 3c222f3..ca070a3 100644
--- a/src/lua/embed/mouse.lua.h
+++ b/src/lua/embed/scripts/mouse.lua.h
@@ -1,6 +1,8 @@
static const char* mouse_lua = R"(
jin.mouse = jin.mouse or {}
+local jm = jin.mouse
+
local button = {}
function jin.mouse.isDown(btn)
diff --git a/src/lua/embed/net.lua.h b/src/lua/embed/scripts/net.lua.h
index 4d89dc7..a986ce6 100644
--- a/src/lua/embed/net.lua.h
+++ b/src/lua/embed/scripts/net.lua.h
@@ -1,4 +1,7 @@
/* net.lua */
static const char* net_lua = R"(
jin.net = jin.net or {}
+
+local jn = jin.net
+
)"; \ No newline at end of file
diff --git a/src/lua/embed/path.lua.h b/src/lua/embed/scripts/path.lua.h
index 648adf8..f7e1ec3 100644
--- a/src/lua/embed/path.lua.h
+++ b/src/lua/embed/scripts/path.lua.h
@@ -2,6 +2,8 @@
static const char* path_lua = R"(
jin.path = jin.path or {}
+local jp = jin.path
+
-- game root directory
jin._root = nil
diff --git a/src/lua/jin.cpp b/src/lua/jin.cpp
index faae9b2..d9f685b 100644
--- a/src/lua/jin.cpp
+++ b/src/lua/jin.cpp
@@ -1,39 +1,40 @@
-#include "jin.h"
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "embed/embed.h"
+#include "jin.h"
namespace JinEngine
{
namespace Lua
{
- extern int luaopen_core(lua_State* L);
- extern int luaopen_graphics(lua_State* L);
- extern int luaopen_audio(lua_State* L);
- extern int luaopen_net(lua_State* L);
- extern int luaopen_event(lua_State* L);
- extern int luaopen_time(lua_State* L);
- extern int luaopen_mouse(lua_State* L);
- extern int luaopen_keyboard(lua_State* L);
- extern int luaopen_filesystem(lua_State* L);
- extern int luaopen_joypad(lua_State* L);
- extern int luaopen_math(lua_State* L);
- extern int luaopen_thread(lua_State* L);
- extern int luaopen_bit(lua_State* L);
+ LUA_PORT int luaopen_core(lua_State* L);
+ LUA_PORT int luaopen_graphics(lua_State* L);
+ LUA_PORT int luaopen_audio(lua_State* L);
+ LUA_PORT int luaopen_net(lua_State* L);
+ LUA_PORT int luaopen_event(lua_State* L);
+ LUA_PORT int luaopen_time(lua_State* L);
+ LUA_PORT int luaopen_mouse(lua_State* L);
+ LUA_PORT int luaopen_keyboard(lua_State* L);
+ LUA_PORT int luaopen_filesystem(lua_State* L);
+ LUA_PORT int luaopen_joypad(lua_State* L);
+ LUA_PORT int luaopen_math(lua_State* L);
+ LUA_PORT int luaopen_thread(lua_State* L);
+ LUA_PORT int luaopen_bit(lua_State* L);
- static int l_getversion(lua_State* L)
+ LUA_IMPLEMENT int l_getversion(lua_State* L)
{
luax_pushstring(L, VERSION);
return 1;
}
- static int l_getAuthor(lua_State* L)
+ LUA_IMPLEMENT int l_getAuthor(lua_State* L)
{
luax_pushstring(L, AUTHOR);
return 1;
}
- static int l_getOS(lua_State* L)
+ LUA_IMPLEMENT int l_getOS(lua_State* L)
{
#ifdef _WIN32
luax_pushstring(L, "windows");
@@ -45,65 +46,64 @@ namespace JinEngine
return 1;
}
- static int l_revision(lua_State* L)
+ LUA_IMPLEMENT int l_revision(lua_State* L)
{
luax_pushnumber(L, REVISION);
return 1;
}
- static const luax_Str s[] = {
+ LUA_IMPLEMENT const luax_Str s[] = {
{ "version", VERSION },
{ "author", AUTHOR },
{ "codename", CODE_NAME },
{ 0, 0 }
};
- static const luax_Num n[] = {
+ LUA_IMPLEMENT const luax_Num n[] = {
{ "revision", REVISION },
{ 0, 0 }
};
- /* sub modules */
- static const luax_Ref mods[] = {
- { "core", luaopen_core },
- { "event", luaopen_event },
- { "graphics", luaopen_graphics },
- { "time", luaopen_time },
- { "mouse", luaopen_mouse },
- { "keyboard", luaopen_keyboard },
- { "filesystem", luaopen_filesystem },
- { "net", luaopen_net },
- { "audio", luaopen_audio },
- { "joypad", luaopen_joypad },
- { "math", luaopen_math },
- { "thread", luaopen_thread },
- { "bit", luaopen_bit },
- //{"ai", luaopen_ai },
- { 0, 0 }
- };
-
/* register jin module, keep it on the top of stack */
- int luaopen_jin(lua_State* L)
+ LUA_EXPORT int luaopen_jin(lua_State* L)
{
luax_globaltable(L, MODULE_NAME);
- /* register values */
+ // Register values.
luax_setfieldstrings(L, s);
luax_setfieldnumbers(L, n);
- /* register submodules */
- for (int i = 0; mods[i].name; ++i)
+ luax_Reg modules[] = {
+ { "core", luaopen_core },
+ { "event", luaopen_event },
+ { "graphics", luaopen_graphics },
+ { "time", luaopen_time },
+ { "mouse", luaopen_mouse },
+ { "keyboard", luaopen_keyboard },
+ { "filesystem", luaopen_filesystem },
+ { "net", luaopen_net },
+ { "audio", luaopen_audio },
+ { "joypad", luaopen_joypad },
+ { "math", luaopen_math },
+ { "thread", luaopen_thread },
+ { "bit", luaopen_bit },
+ //{"ai", luaopen_ai },
+ { 0, 0 }
+ };
+
+ // Register sub modules.
+ for (int i = 0; modules[i].name; ++i)
{
- mods[i].func(L);
- luax_setfield(L, -2, mods[i].name);
+ modules[i].func(L);
+ luax_setfield(L, -2, modules[i].name);
}
return 1;
}
- void boot(lua_State* L)
+ LUA_EXPORT void boot(lua_State* L)
{
- JinEngine::embed::boot(L);
+ JinEngine::Embed::boot(L);
}
} // namespace Lua
diff --git a/src/lua/jin.h b/src/lua/jin.h
index 71ad51b..a4dcd3e 100644
--- a/src/lua/jin.h
+++ b/src/lua/jin.h
@@ -4,6 +4,7 @@
#ifndef __JIN_M_JIN_H
#define __JIN_M_JIN_H
+#include "lua/common/je_lua_common.h"
#include "luax.h"
#define MODULE_NAME "jin"
@@ -21,12 +22,12 @@ namespace JinEngine
///
/// open jin module.
///
- int luaopen_jin(lua_State* L);
+ LUA_EXPORT int luaopen_jin(lua_State* L);
///
/// Boot jin.
///
- void boot(lua_State* L);
+ LUA_EXPORT void boot(lua_State* L);
} // namespace JinEngine
} // namespace Lua
diff --git a/src/lua/libraries/luax/luax.h b/src/lua/libraries/luax/luax.h
index fd10737..311bc95 100644
--- a/src/lua/libraries/luax/luax.h
+++ b/src/lua/libraries/luax/luax.h
@@ -40,13 +40,13 @@
#define luax_pcall lua_pcall
#define luax_setglobal lua_setglobal
#define luax_setglobali(L, i, name)\
-lua_pushvalue(L, i);\
-lua_setglobal(L, name);
+ lua_pushvalue(L, i);\
+ lua_setglobal(L, name);
#define luax_pop lua_pop
#define luax_newtable lua_newtable
#define luax_getglobal lua_getglobal
-#define luax_clear(L) lua_settop(L, 0)
+#define luax_clearstack(L) lua_settop(L, 0)
/**
*
*/
@@ -89,6 +89,14 @@ inline bool luax_checkbool(lua_State *L, int numArg)
*/
/* get value and leaves it on top of stack */
#define luax_rawgetnumber(L, i, k) (lua_rawgeti(L,i, k), lua_tonumber(L, -1))
+inline float luax_rawgetnumberthenpop(lua_State* L, int i, int k)
+{
+ float n = luax_rawgetnumber(L, i, k);
+ luax_pop(L, 1);
+ return n;
+}
+
+#define luax_rawgeti lua_rawgeti
/**
*
@@ -111,6 +119,7 @@ inline bool luax_checkbool(lua_State *L, int numArg)
#define luax_pushboolean lua_pushboolean
#define luax_pushlightuserdata lua_pushlightuserdata
#define luax_pushnil lua_pushnil
+#define luax_pushvalue lua_pushvalue
//inline void luax_pushuserdata(lua_State* L, void* p)
//{
@@ -168,6 +177,10 @@ inline char luax_getfieldbool(lua_State* L, int I, const char* N)
char bin = lua_toboolean(L, -1);
return bin;
}
+/**
+*
+*/
+#define luax_call lua_call
/**
* Set raw
@@ -270,6 +283,7 @@ inline int luax_istype(lua_State* L, int idx, const char* tname)
#define luax_istable(L, i) luax_is(table, L, i)
#define luax_isnil(L, i) luax_is(nil, L, i)
#define luax_isboolean(L, i) luax_is(boolean, L, i)
+#define luax_isfunction(L, i) luax_is(function, L, i)
#define luax_isuserdata lua_isuserdata
#define luax_islightuserdata lua_islightuserdata
inline int luax_isinteger(lua_State* L, int i)
@@ -417,7 +431,11 @@ inline void luax_setfieldnumbers(lua_State* L, const luax_Num* strs)
}
}
-typedef luaL_Reg luax_Ref;
+typedef luaL_Reg luax_Reg;
+
+#define luax_ref luaL_ref
+
+#define luax_unref luaL_unref
#endif // #if LUA_VERSION_NUM == 501
diff --git a/src/lua/main.cpp b/src/lua/main.cpp
deleted file mode 100644
index 95862ec..0000000
--- a/src/lua/main.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#ifdef _WIN32
- #include <SDL2/SDL_Main.h>
- #include <direct.h>
-#endif
-
-#include "luax.h"
-#include "jin.h"
-#include "libjin/jin.h"
-#include <Windows.h>
-
-using namespace JinEngine::Lua;
-using namespace JinEngine::Filesystem;
-
-int main(int argc, char* argv[])
-{
- lua_State* L = luax_newstate();
-
- /* open lua standard module */
- luax_openlibs(L);
- /* open jin module */
- luaopen_jin(L);
- /* add args to field */
- luax_newtable(L);
- for (int i = 0; i < argc; ++i)
- luax_setrawstring(L, -2, i + 1, argv[i]);
- luax_setfield(L, -2, "args");
- /* push current working directory */
- /* absolute directory */
- Buffer cwd = Buffer(1024);
-#ifdef _WIN32
- _getcwd((char*)&cwd, cwd.size());
-#elif defined __unix__
-#elif defined __APPLE__
-#endif
- luax_setfieldstring(L, "cwd", (char*)&cwd);
- luax_clear(L);
-
- /* boot jin and run it */
- boot(L);
-
- luax_close(L);
-
- return 0;
-} \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_ai.cpp b/src/lua/modules/ai/je_lua_ai.cpp
new file mode 100644
index 0000000..4afd625
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_ai.cpp
@@ -0,0 +1,13 @@
+#include "libjin/jin.h"
+
+using namespace JinEngine::AI;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_ai.h b/src/lua/modules/ai/je_lua_ai.h
new file mode 100644
index 0000000..036bc3f
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_ai.h
@@ -0,0 +1,7 @@
+#ifndef __JE_LUA_AI_H__
+#define __JE_LUA_AI_H__
+
+#include "je_lua_behavior_tree.h"
+#include "je_lua_state_machine.h"
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_behavior_tree.cpp b/src/lua/modules/ai/je_lua_behavior_tree.cpp
new file mode 100644
index 0000000..20e8e55
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_behavior_tree.cpp
@@ -0,0 +1,11 @@
+#include "libjin/jin.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_BehaviorTree = "Texture";
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_behavior_tree.h b/src/lua/modules/ai/je_lua_behavior_tree.h
new file mode 100644
index 0000000..083d12b
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_behavior_tree.h
@@ -0,0 +1,14 @@
+#ifndef __JE_LUA_BEHAVIOR_TREE_H__
+#define __JE_LUA_BEHAVIOR_TREE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_BehaviorTree;
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_state_machine.cpp b/src/lua/modules/ai/je_lua_state_machine.cpp
new file mode 100644
index 0000000..86ce7a5
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_state_machine.cpp
@@ -0,0 +1,25 @@
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+using namespace JinEngine::AI;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_StateMachine = "StateMachine";
+
+ LUA_IMPLEMENT int l_addEnterCallback(lua_State* L)
+ {
+ //StateMachine* sm;
+ //sm->addEnterListener("", [](void* p) -> void{
+
+ //
+ //});
+
+ return 0;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_state_machine.h b/src/lua/modules/ai/je_lua_state_machine.h
new file mode 100644
index 0000000..3c78f75
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_state_machine.h
@@ -0,0 +1,14 @@
+#ifndef __JE_LUA_STATE_MACHINE_H__
+#define __JE_LUA_STATE_MACHINE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_StateMachine;
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/audio/audio.cpp b/src/lua/modules/audio/audio.cpp
deleted file mode 100644
index 198323d..0000000
--- a/src/lua/modules/audio/audio.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Audio;
- using namespace JinEngine::Filesystem;
-
- typedef SDLAudio Audio;
- typedef SDLSource Source;
-
- static int l_init(lua_State* L)
- {
- Audio::Setting setting;
- setting.samplerate = 44100;
- setting.samples = 44100;
- if (!Audio::get()->init(&setting))
- {
- luax_error(L, "could not init audio");
- luax_pushboolean(L, false);
- return 1;
- }
- luax_pushboolean(L, true);
- return 1;
- }
-
- static int l_play(lua_State* L)
- {
- Audio::get()->play();
- return 0;
- }
-
- static int l_stop(lua_State* L)
- {
- Audio::get()->stop();
- return 0;
- }
-
- static int l_pause(lua_State* L)
- {
- Audio::get()->pause();
- return 0;
- }
-
- static int l_resume(lua_State* L)
- {
- Audio::get()->resume();
- return 0;
- }
-
- static int l_setVolume(lua_State* L)
- {
- float volume = luax_checknumber(L, 1);
- Audio::get()->setVolume(volume);
- return 0;
- }
-
- static int l_newSource(lua_State* L)
- {
- AssetDatabase* fs = AssetDatabase::get();
- const char* f = luax_checkstring(L, 1);
- Buffer b;
- if (!fs->exists(f))
- {
- error(L, "No such image %s", f);
- goto fail;
- }
- if (!fs->read(f, b))
- {
- error(L, "Failed to read source file %s", f);
- goto fail;
- }
- Source* src = Source::createSource((void*)&b, b.size());
- if (src == nullptr)
- {
- error(L, "Failed to decode source file %s", f);
- goto fail;
- }
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_AUDIO_SOURCE, sizeof(Proxy));
- proxy->bind(new Ref<Source>(src, JIN_AUDIO_SOURCE));
- return 1;
- fail:
- luax_pushnil(L);
- return 1;
- }
-
- static int l_destroy(lua_State* L)
- {
- Audio* audio = Audio::get();
- audio->quit();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "init", l_init },
- { "play", l_play },
- { "stop", l_stop },
- { "pause", l_pause },
- { "resume", l_resume },
- { "setVolume", l_setVolume },
- { "newSource", l_newSource },
- { "destroy", l_destroy },
- { 0, 0 }
- };
-
- extern int luaopen_Source(lua_State* L);
-
- int luaopen_audio(lua_State* L)
- {
- luaopen_Source(L);
-
- luax_newlib(L, f);
-
- return 1;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/audio/je_lua_audio.cpp b/src/lua/modules/audio/je_lua_audio.cpp
new file mode 100644
index 0000000..50c5268
--- /dev/null
+++ b/src/lua/modules/audio/je_lua_audio.cpp
@@ -0,0 +1,135 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_source.h"
+
+using namespace JinEngine::Audio;
+using namespace JinEngine::Audio::SDL;
+using namespace JinEngine::Filesystem;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ typedef SDLAudio Audio;
+ typedef SDLSource Source;
+
+ struct
+ {
+ bool initialized = false;
+ } context;
+
+ LUA_IMPLEMENT int l_init(lua_State* L)
+ {
+ if (context.initialized)
+ {
+ // Already initialized.
+ luax_pushboolean(L, true);
+ return 1;
+ }
+ Audio::Setting setting;
+ setting.samplerate = 44100;
+ setting.samples = 44100;
+ context.initialized = Audio::get()->init(&setting);
+ if (!context.initialized)
+ {
+ luax_error(L, "could not init audio");
+ luax_pushboolean(L, false);
+ return 1;
+ }
+ luax_pushboolean(L, true);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_play(lua_State* L)
+ {
+ Audio::get()->play();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_stop(lua_State* L)
+ {
+ Audio::get()->stop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pause(lua_State* L)
+ {
+ Audio::get()->pause();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_resume(lua_State* L)
+ {
+ Audio::get()->resume();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setVolume(lua_State* L)
+ {
+ float volume = luax_checknumber(L, 1);
+ Audio::get()->setVolume(volume);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newSource(lua_State* L)
+ {
+ AssetDatabase* fs = AssetDatabase::get();
+ const char* f = luax_checkstring(L, 1);
+ Buffer b;
+ try
+ {
+ if (!fs->exists(f))
+ throw Exception("No such source file %s.", f);
+ fs->read(f, b);
+ }
+ catch (Exception& e)
+ {
+ error(L, "Failed to read source file %s", f);
+ luax_pushnil(L);
+ return 1;
+ }
+ Source* src = Source::createSource((void*)&b, b.size());
+ if (src == nullptr)
+ {
+ error(L, "Failed to decode source file %s", f);
+ luax_pushnil(L);
+ return 1;
+ }
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Source);
+ proxy->bind(new Shared<Source>(src, Jin_Lua_Source));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_destroy(lua_State* L)
+ {
+ Audio* audio = Audio::get();
+ audio->quit();
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_audio(lua_State* L)
+ {
+ luaopen_Source(L);
+
+ luaL_Reg f[] = {
+ { "init", l_init },
+ { "play", l_play },
+ { "stop", l_stop },
+ { "pause", l_pause },
+ { "resume", l_resume },
+ { "setVolume", l_setVolume },
+ { "newSource", l_newSource },
+ { "destroy", l_destroy },
+ { 0, 0 }
+ };
+
+ luax_newlib(L, f);
+
+ return 1;
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/audio/je_lua_audio.h b/src/lua/modules/audio/je_lua_audio.h
new file mode 100644
index 0000000..fa66392
--- /dev/null
+++ b/src/lua/modules/audio/je_lua_audio.h
@@ -0,0 +1,6 @@
+#ifndef __JE_LUA_AUDIO_H__
+#define __JE_LUA_AUDIO_H__
+
+#include "je_lua_audio.h"
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/audio/je_lua_source.cpp b/src/lua/modules/audio/je_lua_source.cpp
new file mode 100644
index 0000000..e152847
--- /dev/null
+++ b/src/lua/modules/audio/je_lua_source.cpp
@@ -0,0 +1,117 @@
+#include "libjin/jin.h"
+#include "lua/modules/luax.h"
+#include "lua/common/je_lua_common.h"
+
+
+using namespace JinEngine::Audio;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Source = "Source";
+
+ typedef Shared<Source>& SharedSource;
+
+ LUA_IMPLEMENT inline SharedSource checkSource(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Source);
+ return proxy->getShared<Source>();
+ }
+
+ LUA_IMPLEMENT int l_play(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->play();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_stop(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->stop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pause(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->pause();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_rewind(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->rewind();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_resume(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->resume();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_isStop(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ bool isStop = shared->isStopped();
+ luax_pushboolean(L, isStop);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_isPaused(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ bool isPaused = shared->isPaused();
+ luax_pushboolean(L, isPaused);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_setVolume(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ float volume = luax_checknumber(L, 2);
+ shared->setVolume(volume);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setLoop(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ bool loop = luax_checkbool(L, 2);
+ shared->setLoop(loop);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Source);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Source(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "play", l_play },
+ { "stop", l_stop },
+ { "pause", l_pause },
+ { "resume", l_resume },
+ { "rewind", l_rewind },
+ { "isStop", l_isStop },
+ { "isPaused", l_isPaused },
+ { "setVolume", l_setVolume },
+ { "setLoop", l_setLoop },
+ { 0, 0 }
+ };
+
+ luax_newtype(L, Jin_Lua_Source, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/audio/je_lua_source.h b/src/lua/modules/audio/je_lua_source.h
new file mode 100644
index 0000000..f7e6b48
--- /dev/null
+++ b/src/lua/modules/audio/je_lua_source.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_SOURCE_H__
+#define __JE_LUA_SOURCE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Source;
+
+ void luaopen_Source(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/audio/source.cpp b/src/lua/modules/audio/source.cpp
deleted file mode 100644
index bf43ceb..0000000
--- a/src/lua/modules/audio/source.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-#include "libjin/jin.h"
-#include "lua/modules/luax.h"
-#include "lua/common/common.h"
-#include "lua/modules/types.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Audio;
-
- typedef Ref<Source>& SourceRef;
-
- static inline SourceRef checkSource(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE);
- return proxy->getRef<Source>();
- }
-
- static int l_play(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->play();
- return 0;
- }
-
- static int l_stop(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->stop();
- return 0;
- }
-
- static int l_pause(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->pause();
- return 0;
- }
-
- static int l_rewind(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->rewind();
- return 0;
- }
-
- static int l_resume(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->resume();
- return 0;
- }
-
- static int l_isStop(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- bool isStop = ref->isStopped();
- luax_pushboolean(L, isStop);
- return 1;
- }
-
- static int l_isPaused(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- bool isPaused = ref->isPaused();
- luax_pushboolean(L, isPaused);
- return 1;
- }
-
- static int l_setVolume(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- float volume = luax_checknumber(L, 2);
- ref->setVolume(volume);
- return 0;
- }
-
- static int l_setLoop(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- bool loop = luax_checkbool(L, 2);
- ref->setLoop(loop);
- return 0;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "play", l_play },
- { "stop", l_stop },
- { "pause", l_pause },
- { "resume", l_resume },
- { "rewind", l_rewind },
- { "isStop", l_isStop },
- { "isPaused", l_isPaused },
- { "setVolume", l_setVolume },
- { "setLoop", l_setLoop },
- { 0, 0 }
- };
-
- int luaopen_Source(lua_State* L)
- {
- luax_newtype(L, JIN_AUDIO_SOURCE, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/bit/bit.cpp b/src/lua/modules/bit/je_lua_bit.cpp
index cedd60a..fdd0ae0 100644
--- a/src/lua/modules/bit/bit.cpp
+++ b/src/lua/modules/bit/je_lua_bit.cpp
@@ -1,5 +1,7 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
+
#include <cstdlib>
namespace JinEngine
@@ -7,7 +9,7 @@ namespace JinEngine
namespace Lua
{
- static int l_and(lua_State* L)
+ LUA_IMPLEMENT int l_and(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -15,7 +17,7 @@ namespace JinEngine
return 1;
}
- static int l_or(lua_State* L)
+ LUA_IMPLEMENT int l_or(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -23,7 +25,7 @@ namespace JinEngine
return 1;
}
- static int l_xor(lua_State* L)
+ LUA_IMPLEMENT int l_xor(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -31,14 +33,14 @@ namespace JinEngine
return 1;
}
- static int l_not(lua_State* L)
+ LUA_IMPLEMENT int l_not(lua_State* L)
{
int n = luax_checkinteger(L, 1);
luax_pushinteger(L, ~n);
return 1;
}
- static int l_lshift(lua_State* L)
+ LUA_IMPLEMENT int l_lshift(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -46,7 +48,7 @@ namespace JinEngine
return 1;
}
- static int l_rshift(lua_State* L)
+ LUA_IMPLEMENT int l_rshift(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -54,7 +56,7 @@ namespace JinEngine
return 1;
}
- static int l_include(lua_State* L)
+ LUA_IMPLEMENT int l_include(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -62,19 +64,20 @@ namespace JinEngine
return 1;
}
- static const luaL_Reg f[] = {
- { "bAnd", l_and },
- { "bOr" , l_or },
- { "bXor", l_xor },
- { "bNot", l_not },
- { "bLs", l_lshift },
- { "bRs", l_rshift },
- { "bInc", l_include },
- { 0, 0 }
- };
-
- int luaopen_bit(lua_State* L)
+
+ LUA_EXPORT int luaopen_bit(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "bAnd", l_and },
+ { "bOr" , l_or },
+ { "bXor", l_xor },
+ { "bNot", l_not },
+ { "bLs", l_lshift },
+ { "bRs", l_rshift },
+ { "bInc", l_include },
+ { 0, 0 }
+ };
+
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/bit/je_lua_bit.h b/src/lua/modules/bit/je_lua_bit.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/bit/je_lua_bit.h
diff --git a/src/lua/modules/core/core.cpp b/src/lua/modules/core/core.cpp
deleted file mode 100644
index a576bec..0000000
--- a/src/lua/modules/core/core.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#include "lua/modules/luax.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Core;
-
- static int l_running(lua_State* L)
- {
- static Game* game = Game::get();
- bool running = game->running();
- luax_pushboolean(L, running);
- return 1;
- }
-
- static int l_stop(lua_State* L)
- {
- Game::get()->stop();
- return 0;
- }
-
- static int l_quit(lua_State* L)
- {
- Game::get()->quit();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "running", l_running },
- { "stop", l_stop },
- { "quit", l_quit },
- { 0, 0 }
- };
-
- int luaopen_core(lua_State* L)
- {
- luax_newlib(L, f);
-
- return 1;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/core/je_lua_core.cpp b/src/lua/modules/core/je_lua_core.cpp
new file mode 100644
index 0000000..f5b06c3
--- /dev/null
+++ b/src/lua/modules/core/je_lua_core.cpp
@@ -0,0 +1,46 @@
+#include "lua/common/je_lua_common.h"
+#include "lua/modules/luax.h"
+#include "libjin/jin.h"
+
+using namespace JinEngine::Game;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ LUA_IMPLEMENT int l_running(lua_State* L)
+ {
+ static Application* app = Application::get();
+ bool running = app->running();
+ luax_pushboolean(L, running);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_stop(lua_State* L)
+ {
+ Application::get()->stop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_quit(lua_State* L)
+ {
+ Application::get()->quit();
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_core(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "running", l_running },
+ { "stop", l_stop },
+ { "quit", l_quit },
+ { 0, 0 }
+ };
+ luax_newlib(L, f);
+
+ return 1;
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/core/je_lua_core.h b/src/lua/modules/core/je_lua_core.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/core/je_lua_core.h
diff --git a/src/lua/modules/event/event.cpp b/src/lua/modules/event/je_lua_event.cpp
index 9f565d0..82ba385 100644
--- a/src/lua/modules/event/event.cpp
+++ b/src/lua/modules/event/je_lua_event.cpp
@@ -1,21 +1,22 @@
/**
* Event module
*/
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
+using namespace JinEngine;
+using namespace JinEngine::Input;
+
namespace JinEngine
{
namespace Lua
{
- using namespace JinEngine;
- using namespace JinEngine::Input;
-
/**
* Load event poll, return a iterator(a table).
*/
- static int l_event_poll(lua_State *L)
+ LUA_IMPLEMENT int l_event_poll(lua_State *L)
{
/* table to store events */
luax_newtable(L);
@@ -100,10 +101,9 @@ namespace JinEngine
case EventType::CONTROLLERAXISMOTION:
-
default:
- /* ignore other events */
- luax_pop(L, 1); // pop table out
+ // Ignore oter events and pop up the event table.
+ luax_pop(L, 1);
goto poll;
break;
}
@@ -111,18 +111,18 @@ namespace JinEngine
}
return 1;
}
-
- static const luaL_Reg f[] = {
- { "poll", l_event_poll },
- { 0, 0 }
- };
/**
* load event module
*/
- int luaopen_event(lua_State* L)
+ LUA_EXPORT int luaopen_event(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "poll", l_event_poll },
+ { 0, 0 }
+ };
luax_newlib(L, f);
+
return 1;
}
diff --git a/src/lua/modules/event/je_lua_event.h b/src/lua/modules/event/je_lua_event.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/event/je_lua_event.h
diff --git a/src/lua/modules/filesystem/filesystem.cpp b/src/lua/modules/filesystem/je_lua_filesystem.cpp
index 7466ce8..6245ba8 100644
--- a/src/lua/modules/filesystem/filesystem.cpp
+++ b/src/lua/modules/filesystem/je_lua_filesystem.cpp
@@ -1,3 +1,4 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
#include <string>
@@ -9,25 +10,25 @@ namespace JinEngine
namespace Lua
{
- static struct
+ LUA_IMPLEMENT struct
{
AssetDatabase* fs;
} context;
- static int l_init(lua_State* L)
+ LUA_IMPLEMENT int l_init(lua_State* L)
{
context.fs = AssetDatabase::get();
return 0;
}
- static int l_mount(lua_State* L)
+ LUA_IMPLEMENT int l_mount(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
context.fs->mount(path);
return 0;
}
- static int l_exist(lua_State * L)
+ LUA_IMPLEMENT int l_exist(lua_State * L)
{
const char* path = luax_checkstring(L, 1);
int r = context.fs->exists(path);
@@ -35,7 +36,7 @@ namespace JinEngine
return 1;
}
- static int l_isDir(lua_State* L)
+ LUA_IMPLEMENT int l_isDir(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
int r = context.fs->isDir(path);
@@ -43,7 +44,7 @@ namespace JinEngine
return 1;
}
- static int l_isFile(lua_State* L)
+ LUA_IMPLEMENT int l_isFile(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
int r = context.fs->isFile(path);
@@ -51,7 +52,7 @@ namespace JinEngine
return 1;
}
- static int loadbuffer(lua_State* L)
+ LUA_IMPLEMENT int loadbuffer(lua_State* L)
{
const char* filename = lua_tostring(L, -1);
Buffer bf;
@@ -60,7 +61,7 @@ namespace JinEngine
return 1;
}
- static int loader(lua_State* L)
+ LUA_IMPLEMENT int loader(lua_State* L)
{
const char * filename = lua_tostring(L, -1);
@@ -107,7 +108,7 @@ namespace JinEngine
return 1;
}
- static int l_read(lua_State* L)
+ LUA_IMPLEMENT int l_read(lua_State* L)
{
AssetDatabase* fs = context.fs;
const char* file = luax_checkstring(L, 1);
@@ -119,20 +120,20 @@ namespace JinEngine
return 2;
}
- static const luaL_Reg f[] = {
- { "init", l_init },
- { "mount", l_mount },
- { "isDirectory", l_isDir },
- { "isFile", l_isFile },
- { "exist", l_exist },
- { "read", l_read },
- { 0, 0 }
- };
-
- int luaopen_filesystem(lua_State* L)
+ LUA_EXPORT int luaopen_filesystem(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "init", l_init },
+ { "mount", l_mount },
+ { "isDirectory", l_isDir },
+ { "isFile", l_isFile },
+ { "exist", l_exist },
+ { "read", l_read },
+ { 0, 0 }
+ };
luax_newlib(L, f);
luax_registersearcher(L, loader, 1);
+
return 0;
}
diff --git a/src/lua/modules/filesystem/je_lua_filesystem.h b/src/lua/modules/filesystem/je_lua_filesystem.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/filesystem/je_lua_filesystem.h
diff --git a/src/lua/modules/graphics/bitmap.cpp b/src/lua/modules/graphics/bitmap.cpp
deleted file mode 100644
index 13517f9..0000000
--- a/src/lua/modules/graphics/bitmap.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Bitmap>& BitmapRef;
-
- static inline BitmapRef checkBitmap(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
- return proxy->getRef<Bitmap>();
- }
-
- static int l_gc(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- ref.release();
- return 0;
- }
-
- static int l_getWidth(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int w = ref->getWidth();
- luax_pushinteger(L, w);
- return 1;
- }
-
- static int l_getHeight(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int h = ref->getHeight();
- luax_pushinteger(L, h);
- return 1;
- }
-
- static int l_getSize(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int w = ref->getWidth();
- int h = ref->getHeight();
- luax_pushinteger(L, w);
- luax_pushinteger(L, h);
- return 2;
- }
-
- static int l_getPixel(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int x = luax_checkinteger(L, 2);
- int y = luax_checkinteger(L, 3);
- Color col = ref->getPixel(x, y);
- luax_pushinteger(L, col.r);
- luax_pushinteger(L, col.g);
- luax_pushinteger(L, col.b);
- luax_pushinteger(L, col.a);
- return 4;
- }
-
- static int l_setPixel(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int x = luax_checkinteger(L, 2);
- int y = luax_checkinteger(L, 3);
- if (!luax_istable(L, 4))
- {
- luax_typerror(L, 4, "table");
- return 1;
- }
- unsigned int r = luax_rawgetnumber(L, 4, 1);
- unsigned int g = luax_rawgetnumber(L, 4, 2);
- unsigned int b = luax_rawgetnumber(L, 4, 3);
- unsigned int a = luax_rawgetnumber(L, 4, 4);
- ref->setPixel(Color(r, g, b, a), x, y);
- return 0;
- }
-
- static int l_clone(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- Bitmap* bitmap = ref.getObject();
- Bitmap* b = Bitmap::clone(bitmap);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
- proxy->bind(new Ref<Bitmap>(b, JIN_GRAPHICS_BITMAP));
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { "getPixel", l_getPixel },
- { "setPixel", l_setPixel },
- { "clone", l_clone },
- { 0, 0 }
- };
-
- int luaopen_Bitmap(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_BITMAP, f);
- return 0;
- }
-
- } // graphics
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/canvas.cpp b/src/lua/modules/graphics/canvas.cpp
deleted file mode 100644
index e49e209..0000000
--- a/src/lua/modules/graphics/canvas.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Canvas>& CanvasRef;
-
- static inline CanvasRef checkCanvas(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- return proxy->getRef<Canvas>();
- }
-
- static int l_getWidth(lua_State* L)
- {
- CanvasRef ref = checkCanvas(L);
- luax_pushnumber(L, ref->getWidth());
- return 1;
- }
-
- static int l_getHeight(lua_State* L)
- {
- CanvasRef ref = checkCanvas(L);
- luax_pushnumber(L, ref->getHeight());
- return 1;
- }
-
- static int l_getSize(lua_State* L)
- {
- CanvasRef ref = checkCanvas(L);
- luax_pushnumber(L, ref->getWidth());
- luax_pushnumber(L, ref->getHeight());
- return 2;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { 0, 0 }
- };
-
- int luaopen_Canvas(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_CANVAS, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_bitmap.cpp b/src/lua/modules/graphics/je_lua_bitmap.cpp
new file mode 100644
index 0000000..6b7655f
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_bitmap.cpp
@@ -0,0 +1,114 @@
+#include "lua/common/je_lua_common.h"
+#include "lua/modules/luax.h"
+
+#include "libjin/jin.h"
+#include "je_lua_bitmap.h"
+
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Bitmap = "Bitmap";
+
+ typedef Shared<Bitmap>& SharedBitmap;
+
+ LUA_IMPLEMENT inline SharedBitmap checkBitmap(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Bitmap);
+ return proxy->getShared<Bitmap>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ shared.release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int w = shared->getWidth();
+ luax_pushinteger(L, w);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int h = shared->getHeight();
+ luax_pushinteger(L, h);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int w = shared->getWidth();
+ int h = shared->getHeight();
+ luax_pushinteger(L, w);
+ luax_pushinteger(L, h);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getPixel(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int x = luax_checkinteger(L, 2);
+ int y = luax_checkinteger(L, 3);
+ Color col = shared->getPixel(x, y);
+ luax_pushinteger(L, col.r);
+ luax_pushinteger(L, col.g);
+ luax_pushinteger(L, col.b);
+ luax_pushinteger(L, col.a);
+ return 4;
+ }
+
+ LUA_IMPLEMENT int l_setPixel(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int x = luax_checkinteger(L, 2);
+ int y = luax_checkinteger(L, 3);
+ if (!luax_istable(L, 4))
+ {
+ luax_typerror(L, 4, "table");
+ return 1;
+ }
+ unsigned int r = luax_rawgetnumber(L, 4, 1);
+ unsigned int g = luax_rawgetnumber(L, 4, 2);
+ unsigned int b = luax_rawgetnumber(L, 4, 3);
+ unsigned int a = luax_rawgetnumber(L, 4, 4);
+ shared->setPixel(Color(r, g, b, a), x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_clone(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ Bitmap* bitmap = shared.getObject();
+ Bitmap* b = Bitmap::clone(bitmap);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap);
+ proxy->bind(new Shared<Bitmap>(b, Jin_Lua_Bitmap));
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_Bitmap(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { "getPixel", l_getPixel },
+ { "setPixel", l_setPixel },
+ { "clone", l_clone },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Bitmap, f);
+ }
+
+ } // namespace Graphics
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_bitmap.h b/src/lua/modules/graphics/je_lua_bitmap.h
new file mode 100644
index 0000000..b463d83
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_bitmap.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_BITMAP_H__
+#define __JE_LUA_BITMAP_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Bitmap;
+
+ void luaopen_Bitmap(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_canvas.cpp b/src/lua/modules/graphics/je_lua_canvas.cpp
new file mode 100644
index 0000000..f7bd650
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_canvas.cpp
@@ -0,0 +1,66 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_canvas.h"
+
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Canvas = "Canvas";
+
+ typedef Shared<Canvas>& SharedCanvas;
+
+ LUA_IMPLEMENT inline SharedCanvas checkCanvas(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ return proxy->getShared<Canvas>();
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ SharedCanvas shared = checkCanvas(L);
+ luax_pushnumber(L, shared->getWidth());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
+ {
+ SharedCanvas shared = checkCanvas(L);
+ luax_pushnumber(L, shared->getHeight());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ SharedCanvas shared = checkCanvas(L);
+ luax_pushnumber(L, shared->getWidth());
+ luax_pushnumber(L, shared->getHeight());
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Canvas(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Canvas, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_canvas.h b/src/lua/modules/graphics/je_lua_canvas.h
new file mode 100644
index 0000000..d1fa885
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_canvas.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_CANVAS_H__
+#define __JE_LUA_CANVAS_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Canvas;
+
+ void luaopen_Canvas(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 8b2d7cd..ce569d0 100644
--- a/src/lua/modules/graphics/graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -3,14 +3,27 @@
#include "libjin/jin.h"
#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
+
+#include "lua/common/je_lua_common.h"
+
+#include "je_lua_canvas.h"
+#include "je_lua_sprite.h"
+#include "je_lua_spritesheet.h"
+#include "je_lua_bitmap.h"
+#include "je_lua_ttf.h"
+#include "je_lua_ttf_data.h"
+#include "je_lua_texture.h"
+#include "je_lua_shader.h"
+#include "je_lua_text.h"
+#include "je_lua_texture_font.h"
+#include "je_lua_page.h"
using namespace std;
using namespace JinEngine;
using namespace JinEngine::Graphics;
-using JinEngine::Filesystem::AssetDatabase;
-using JinEngine::Filesystem::Buffer;
+using namespace JinEngine::Graphics::Fonts;
+using namespace JinEngine::Graphics::Shaders;
+using namespace JinEngine::Filesystem;
namespace JinEngine
{
@@ -18,59 +31,52 @@ namespace JinEngine
{
#include "../../resources/font.ttf.h"
-
+
static struct
{
Color curRenderColor;
Color curClearColor;
Font* curFont = nullptr;
Font* defaultFont = nullptr;
+ bool initialized = false;
} context;
- static int l_init(lua_State* L)
+ LUA_IMPLEMENT int l_init(lua_State* L)
{
+ if (context.initialized)
+ {
+ luax_pushboolean(L, true);
+ return 1;
+ }
+
Window* wnd = Window::get();
Window::Setting setting;
setting.width = luax_getfieldinteger(L, 1, "width");
setting.height = luax_getfieldinteger(L, 1, "height");
setting.title = luax_getfieldstring(L, 1, "title");
+ setting.icon = luax_getfieldstring(L, 1, "icon");
setting.vsync = luax_getfieldbool(L, 1, "vsync");
setting.fullscreen = luax_getfieldbool(L, 1, "fullscreen");
setting.resizable = luax_getfieldbool(L, 1, "resizable");
- if (!wnd->init(&setting))
+ context.initialized = wnd->init(&setting);
+ if (!context.initialized)
{
- luax_pushboolean(L, false);
+ luax_pushboolean(L, context.initialized);
return 1;
}
- {
- /* load default font */
- Bitmap* bitmap = Bitmap::createBitmap(default_font_bitmap, sizeof(default_font_bitmap));
- const Color* pixels = bitmap->getPixels();
- ofstream f = ofstream();
- f.open("font.pixels", ios_base::app);
- for (int y = 0; y < bitmap->getHeight(); ++y)
- {
- for (int x = 0; x < bitmap->getWidth(); ++x)
- {
- Color c = pixels[x + y * bitmap->getWidth()];
- f << (int)c.r << ",";
- f << (int)c.g << ",";
- f << (int)c.b << ",";
- f << (int)c.a << ",";
- }
- }
-
- TextureFont* tf = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight());
- context.defaultFont = tf;
- delete bitmap;
- }
- context.curFont = context.defaultFont;
-
- luax_pushboolean(L, true);
+
+ /* load default font */
+ Bitmap* bitmap = Bitmap::createBitmap(default_font_bitmap, sizeof(default_font_bitmap));
+ TextureFont* tf = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight());
+ delete bitmap;
+ context.defaultFont = tf;
+ context.curFont = tf;
+
+ luax_pushboolean(L, context.initialized);
return 1;
}
- static int l_setTitle(lua_State* L)
+ LUA_IMPLEMENT int l_setTitle(lua_State* L)
{
Window* wnd = Window::get();
const char* title = luax_checkstring(L, 1);
@@ -78,14 +84,28 @@ namespace JinEngine
return 0;
}
- static int l_destroy(lua_State* L)
+ LUA_IMPLEMENT int l_destroy(lua_State* L)
{
Window* wnd = Window::get();
wnd->quit();
return 0;
}
-
- static int l_getSize(lua_State* L)
+
+ LUA_IMPLEMENT int l_showWindow(lua_State* L)
+ {
+ Window* wnd = Window::get();
+ wnd->show();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_hideWindow(lua_State* L)
+ {
+ Window* wnd = Window::get();
+ wnd->hide();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
{
Window* wnd = Window::get();
luax_pushnumber(L, wnd->getW());
@@ -93,21 +113,21 @@ namespace JinEngine
return 2;
}
- static int l_getWidth(lua_State* L)
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
{
Window* wnd = Window::get();
luax_pushnumber(L, wnd->getW());
return 1;
}
- static int l_getHeight(lua_State* L)
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
{
Window* wnd = Window::get();
luax_pushnumber(L, wnd->getH());
return 1;
}
- static int l_newBitmap(lua_State* L)
+ LUA_IMPLEMENT int l_newBitmap(lua_State* L)
{
Bitmap* bitmap = nullptr;
if (luax_gettop(L) == 2)
@@ -120,55 +140,82 @@ namespace JinEngine
{
int w = luax_checkinteger(L, 1);
int h = luax_checkinteger(L, 2);
- if (!luax_istable(L, 3))
+ if (luax_istable(L, 3))
{
- luax_typerror(L, 3, "table");
+ unsigned int r = luax_rawgetnumber(L, 3, 1);
+ unsigned int g = luax_rawgetnumber(L, 3, 2);
+ unsigned int b = luax_rawgetnumber(L, 3, 3);
+ unsigned int a = luax_rawgetnumber(L, 3, 4);
+ bitmap = Bitmap::createBitmap(w, h, Color(r, g, b, a));
+ }
+ else if (luax_isfunction(L, 3))
+ {
+ std::function<Color(int, int, int, int)> drawer = [=](int w, int h, int x, int y)->Color{
+ luax_pushvalue(L, 3);
+ luax_pushnumber(L, w);
+ luax_pushnumber(L, h);
+ luax_pushnumber(L, x);
+ luax_pushnumber(L, y);
+ // Call drawer function.
+ luax_call(L, 4, 1);
+ // Get result color.
+ if (!luax_istable(L, -1))
+ luax_error(L, "Return value of bitmap drawer is wrong, should be a color table.");
+ Color c;
+ c.r = luax_rawgetnumberthenpop(L, -1, 1);
+ c.g = luax_rawgetnumberthenpop(L, -1, 2);
+ c.b = luax_rawgetnumberthenpop(L, -1, 3);
+ c.a = luax_rawgetnumberthenpop(L, -1, 4);
+ // Pop return value.
+ luax_pop(L, 1);
+ return c;
+ };
+ bitmap = Bitmap::createBitmap(w, h, drawer);
+ }
+ else
+ {
+ luax_typerror(L, 3, "color table or color setter");
return 1;
}
- unsigned int r = luax_rawgetnumber(L, 3, 1);
- unsigned int g = luax_rawgetnumber(L, 3, 2);
- unsigned int b = luax_rawgetnumber(L, 3, 3);
- unsigned int a = luax_rawgetnumber(L, 3, 4);
- bitmap = Bitmap::createBitmap(w, h, Color(r, g, b, a));
}
else
{
const char* f = luax_checkstring(L, 1);
AssetDatabase* fs = AssetDatabase::get();
- if (!fs->exists(f))
+ Buffer b;
+ try
{
- error(L, "No such image file %s", f);
- goto fail;
+ if (!fs->exists(f))
+ throw Exception("No such image file %s.", f);
+ fs->read(f, b);
}
- Buffer b;
- if (!fs->read(f, b))
+ catch (Exception& e)
{
error(L, "Failed to read image %s", f);
- goto fail;
+ luax_pushnil(L);
+ return 1;
}
bitmap = Bitmap::createBitmap(&b, b.size());
if (bitmap == nullptr)
{
error(L, "Failed to decode image file %s", f);
- goto fail;
+ luax_pushnil(L);
+ return 1;
}
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
- proxy->bind(new Ref<Bitmap>(bitmap, JIN_GRAPHICS_BITMAP));
- return 1;
- fail:
- luax_pushnil(L);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap);
+ proxy->bind(new Shared<Bitmap>(bitmap, Jin_Lua_Bitmap));
return 1;
}
/* jin.graphics.newTexture(bitmap) */
- static int l_newTexture(lua_State* L)
+ LUA_IMPLEMENT int l_newTexture(lua_State* L)
{
Texture* texture = nullptr;
- if (luax_istype(L, 1, JIN_GRAPHICS_BITMAP))
+ if (luax_istype(L, 1, Jin_Lua_Bitmap))
{
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
- Ref<Bitmap>& refBitmap = p->getRef<Bitmap>();
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Bitmap);
+ Shared<Bitmap>& refBitmap = p->getShared<Bitmap>();
Bitmap* bitmap = refBitmap.getObject();
texture = Texture::createTexture(bitmap);
}
@@ -177,12 +224,12 @@ namespace JinEngine
const char* path = luax_checkstring(L, 1);
texture = Texture::createTexture(path);
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTURE, sizeof(Proxy));
- proxy->bind(new Ref<Texture>(texture, JIN_GRAPHICS_TEXTURE));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Texture);
+ proxy->bind(new Shared<Texture>(texture, Jin_Lua_Texture));
return 1;
}
- static int l_newShader(lua_State* L)
+ LUA_IMPLEMENT int l_newShader(lua_State* L)
{
const char* program = luax_checkstring(L, 1);
Shader* jsl = Shader::createShader(program);
@@ -192,18 +239,18 @@ namespace JinEngine
luax_pushnil(L);
return 1;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
- proxy->bind(new Ref<Shader>(jsl, JIN_GRAPHICS_SHADER));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader);
+ proxy->bind(new Shared<Shader>(jsl, Jin_Lua_Shader));
return 1;
}
- static int l_newShaderf(lua_State* L)
+ LUA_IMPLEMENT int l_newShaderf(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
AssetDatabase* fs = AssetDatabase::get();
if (!fs->exists(path))
{
- error(L, "No such shader file %s\n", path);
+ error(L, "No such shader file \"%s\"", path);
luax_pushnil(L);
return 1;
}
@@ -216,28 +263,28 @@ namespace JinEngine
luax_pushnil(L);
return 1;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
- proxy->bind(new Ref<Shader>(jsl, JIN_GRAPHICS_SHADER));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader);
+ proxy->bind(new Shared<Shader>(jsl, Jin_Lua_Shader));
return 1;
}
- static int l_newCanvas(lua_State* L)
+ LUA_IMPLEMENT int l_newCanvas(lua_State* L)
{
int w = luax_checknumber(L, 1);
int h = luax_checknumber(L, 2);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_CANVAS, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Canvas);
Canvas* cvs = Canvas::createCanvas(w, h);
- proxy->bind(new Ref<Canvas>(cvs, JIN_GRAPHICS_CANVAS));
+ proxy->bind(new Shared<Canvas>(cvs, Jin_Lua_Canvas));
return 1;
}
- static int l_clear(lua_State* L)
+ LUA_IMPLEMENT int l_clear(lua_State* L)
{
glClear(GL_COLOR_BUFFER_BIT);
return 0;
}
- static int l_setClearColor(lua_State* L)
+ LUA_IMPLEMENT int l_setClearColor(lua_State* L)
{
if (luax_gettop(L) == 0)
{
@@ -257,15 +304,15 @@ namespace JinEngine
return 0;
}
- static int l_present(lua_State* L)
+ LUA_IMPLEMENT int l_present(lua_State* L)
{
Window::get()->swapBuffers();
return 0;
}
- static void l_draw_texture(lua_State* L)
+ LUA_IMPLEMENT void l_draw_texture(lua_State* L)
{
- if (!luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
+ if (!luax_istype(L, 1, Jin_Lua_Texture))
return;
int x = luax_optnumber(L, 2, 0);
int y = luax_optnumber(L, 3, 0);
@@ -275,13 +322,13 @@ namespace JinEngine
float ox = luax_optnumber(L, 7, 0);
float oy = luax_optnumber(L, 8, 0);
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Texture>& tex = proxy->getRef<Texture>();
- tex->draw(x, y, sx, sy, r, ox, oy);
+ Shared<Texture>& tex = proxy->getShared<Texture>();
+ tex->render(x, y, sx, sy, r, ox, oy);
}
- static void l_draw_canvas(lua_State* L)
+ LUA_IMPLEMENT void l_draw_canvas(lua_State* L)
{
- if (!luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
+ if (!luax_istype(L, 1, Jin_Lua_Canvas))
return;
int x = luax_optnumber(L, 2, 0);
int y = luax_optnumber(L, 3, 0);
@@ -291,14 +338,14 @@ namespace JinEngine
float ox = luax_optnumber(L, 7, 0);
float oy = luax_optnumber(L, 8, 0);
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Canvas>& p = proxy->getRef<Canvas>();
- p->draw(x, y, sx, sy, r, ox, oy);
+ Shared<Canvas>& p = proxy->getShared<Canvas>();
+ p->render(x, y, sx, sy, r, ox, oy);
}
/* jin.graphics.draw(text, font, x, y) */
- static void l_draw_text(lua_State* L)
+ LUA_IMPLEMENT void l_draw_text(lua_State* L)
{
- if (!luax_istype(L, 1, JIN_GRAPHICS_TEXT))
+ if (!luax_istype(L, 1, Jin_Lua_Text))
return;
Proxy* p = (Proxy*)luax_toudata(L, 1);
Text* text = p->getObject<Text>();
@@ -307,12 +354,12 @@ namespace JinEngine
int spacing = luax_optnumber(L, 6, 0);
Font* font = nullptr;
Proxy* p2 = (Proxy*)luax_toudata(L, 2);
- if (luax_istype(L, 2, JIN_GRAPHICS_TEXTUREFONT))
+ if (luax_istype(L, 2, Jin_Lua_TextureFont))
{
TextureFont* tf = p2->getObject<TextureFont>();
font = tf;
}
- else if (luax_istype(L, 2, JIN_GRAPHICS_TTF))
+ else if (luax_istype(L, 2, Jin_Lua_TTF))
{
TTF* ttf = p2->getObject<TTF>();
font = ttf;
@@ -322,31 +369,31 @@ namespace JinEngine
font = context.defaultFont;
}
int lineheight = luax_optnumber(L, 5, font->getFontSize());
- font->print(*text, x, y, lineheight, spacing);
+ font->render(*text, x, y, lineheight, spacing);
}
/* jin.graphics.draw(page, x, y) */
- static void l_draw_page(lua_State* L)
+ LUA_IMPLEMENT void l_draw_page(lua_State* L)
{
- if (!luax_istype(L, 1, JIN_GRAPHICS_PAGE))
+ if (!luax_istype(L, 1, Jin_Lua_Page))
return;
int x = luax_optnumber(L, 2, 0);
int y = luax_optnumber(L, 3, 0);
Proxy* p = (Proxy*)luax_toudata(L, 1);
Page* page = p->getObject<Page>();
Font* font = page->font;
- font->print(page, x, y);
+ font->render(page, x, y);
}
- static int l_draw(lua_State* L)
+ LUA_IMPLEMENT int l_draw(lua_State* L)
{
- if (luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
+ if (luax_istype(L, 1, Jin_Lua_Texture))
l_draw_texture(L);
- else if (luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
+ else if (luax_istype(L, 1, Jin_Lua_Canvas))
l_draw_canvas(L);
- else if (luax_istype(L, 1, JIN_GRAPHICS_TEXT))
+ else if (luax_istype(L, 1, Jin_Lua_Text))
l_draw_text(L);
- else if (luax_istype(L, 1, JIN_GRAPHICS_PAGE))
+ else if (luax_istype(L, 1, Jin_Lua_Page))
l_draw_page(L);
else
{
@@ -357,7 +404,7 @@ namespace JinEngine
}
// draw(tex, quad, x, y, sx, sy, r, ax, ay)
- static int l_drawq(lua_State* L)
+ LUA_IMPLEMENT int l_drawq(lua_State* L)
{
if (!luax_istable(L, 2))
{
@@ -378,17 +425,17 @@ namespace JinEngine
float ox = luax_optnumber(L, 8, 0);
float oy = luax_optnumber(L, 9, 0);
- if (luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
+ if (luax_istype(L, 1, Jin_Lua_Texture))
{
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Texture>& tex = proxy->getRef<Texture>();
- tex->draw(q, x, y, sx, sy, r, ox, oy);
+ Shared<Texture>& tex = proxy->getShared<Texture>();
+ tex->render(q, x, y, sx, sy, r, ox, oy);
}
- else if (luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
+ else if (luax_istype(L, 1, Jin_Lua_Canvas))
{
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Canvas>& p = proxy->getRef<Canvas>();
- p->draw(q, x, y, sx, sy, r, ox, oy);
+ Shared<Canvas>& p = proxy->getShared<Canvas>();
+ p->render(q, x, y, sx, sy, r, ox, oy);
}
else
{
@@ -398,7 +445,7 @@ namespace JinEngine
/* print(string, x, y, lineheight, spacing) */
/* need set font */
- static int l_print(lua_State* L)
+ LUA_IMPLEMENT int l_print(lua_State* L)
{
Font* font = context.curFont;
if (font == nullptr)
@@ -410,15 +457,15 @@ namespace JinEngine
int y = luax_optnumber(L, 3, 0);
int lineheight = luax_optnumber(L, 4, font->getFontSize());
int spacing = luax_optnumber(L, 5, 0);
- font->print(text, x, y, lineheight, spacing);
+ font->render(text, x, y, lineheight, spacing);
return 0;
}
- static int l_setColor(lua_State* L)
+ LUA_IMPLEMENT int l_setColor(lua_State* L)
{
if (luax_gettop(L) == 0)
{
- glColor4f(1, 1, 1, 1);
+ gl.setColor(Color(255, 255, 255, 255));
return 0;
}
@@ -429,14 +476,11 @@ namespace JinEngine
context.curRenderColor.a = luax_checknumber(L, 4);
else
context.curRenderColor.a = 255;
- glColor4f(context.curRenderColor.r / 255.f,
- context.curRenderColor.g / 255.f,
- context.curRenderColor.b / 255.f,
- context.curRenderColor.a / 255.f);
+ gl.setColor(context.curRenderColor);
return 0;
}
- static int l_getColor(lua_State * L)
+ LUA_IMPLEMENT int l_getColor(lua_State * L)
{
luax_pushnumber(L, context.curRenderColor.r);
luax_pushnumber(L, context.curRenderColor.g);
@@ -445,7 +489,7 @@ namespace JinEngine
return 4;
}
- static int l_bindCanvas(lua_State* L)
+ LUA_IMPLEMENT int l_bindCanvas(lua_State* L)
{
if (luax_gettop(L) == 0)
{
@@ -453,29 +497,29 @@ namespace JinEngine
Canvas::unbind();
return 0;
}
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- Ref<Canvas>& ref = proxy->getRef<Canvas>();
- Canvas::bind(ref.getObject());
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ Shared<Canvas>& shared = proxy->getShared<Canvas>();
+ Canvas::bind(shared.getObject());
return 0;
}
- static int l_unbindCanvas(lua_State* L)
+ LUA_IMPLEMENT int l_unbindCanvas(lua_State* L)
{
Canvas::unbind();
return 0;
}
- static int l_useShader(lua_State* L)
+ LUA_IMPLEMENT int l_useShader(lua_State* L)
{
if (luax_gettop(L) == 0)
{
Shader::unuse();
return 0;
}
- if (luax_istype(L, 1, JIN_GRAPHICS_SHADER))
+ if (luax_istype(L, 1, Jin_Lua_Shader))
{
- Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Shader>& jsl = proxy->getRef<Shader>();
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Shader);
+ Shared<Shader>& jsl = proxy->getShared<Shader>();
jsl->use();
}
else
@@ -485,21 +529,13 @@ namespace JinEngine
return 0;
}
- static int l_setBlend(lua_State* L)
+ LUA_IMPLEMENT int l_setBlend(lua_State* L)
{
return 0;
}
- static RenderMode strtomode(const char* str)
- {
- std::string s = std::string(str);
- if (s == "fill") return RenderMode::FILL;
- else if (s == "line") return RenderMode::LINE;
- else return RenderMode::NONE;
- }
-
- static int l_point(lua_State* L)
+ LUA_IMPLEMENT int l_point(lua_State* L)
{
int x = luax_checknumber(L, 1);
int y = luax_checknumber(L, 2);
@@ -508,7 +544,7 @@ namespace JinEngine
return 0;
}
- static int l_line(lua_State* L)
+ LUA_IMPLEMENT int l_line(lua_State* L)
{
int x1 = luax_checknumber(L, 1);
int y1 = luax_checknumber(L, 2);
@@ -519,10 +555,9 @@ namespace JinEngine
return 0;
}
- static int l_rect(lua_State* L)
+ LUA_IMPLEMENT int l_rect(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = static_cast<RenderMode>(luax_checkinteger(L, 1));
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -540,10 +575,9 @@ namespace JinEngine
return 0;
}
- static int l_circle(lua_State* L)
+ LUA_IMPLEMENT int l_circle(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = static_cast<RenderMode>(luax_checkinteger(L, 1));
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -560,10 +594,9 @@ namespace JinEngine
return 0;
}
- static int l_triangle(lua_State* L)
+ LUA_IMPLEMENT int l_triangle(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = static_cast<RenderMode>(luax_checkinteger(L, 1));
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -586,11 +619,10 @@ namespace JinEngine
return 0;
}
- static int l_polygon(lua_State* L)
+ LUA_IMPLEMENT int l_polygon(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
+ RenderMode mode = static_cast<RenderMode>(luax_checkinteger(L, 1));
int n = luax_checknumber(L, 2);
- RenderMode mode = strtomode(modestr);
if (mode != RenderMode::NONE)
{
if (!luax_istable(L, 3))
@@ -601,7 +633,7 @@ namespace JinEngine
int tn = luax_tableidxlen(L, 3);
if (tn != n * 2)
{
- static char* emsg = \
+ LUA_IMPLEMENT char* emsg = \
"number of polygon vertices doesn't match " \
"provided n, expect %d numbers but get %d";
luax_error(L, emsg, n * 2, tn);
@@ -621,16 +653,16 @@ namespace JinEngine
return 0;
}
- static int l_newTTFData(lua_State* L)
+ LUA_IMPLEMENT int l_newTTFData(lua_State* L)
{
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TTFDATA, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_TTFData);
TTFData* fd = nullptr;
{
const char* path = luax_checkstring(L, 1);
AssetDatabase* fs = AssetDatabase::get();
if (!fs->exists(path))
{
- error(L, "No such font %s\n", path);
+ error(L, "No such font \"%s\"", path);
luax_pushnil(L);
return 1;
}
@@ -638,12 +670,12 @@ namespace JinEngine
fs->read(path, b);
fd = TTFData::createTTFData(&b, b.size());
}
- proxy->bind(new Ref<TTFData>(fd, JIN_GRAPHICS_TTFDATA));
+ proxy->bind(new Shared<TTFData>(fd, Jin_Lua_TTFData));
return 1;
}
-
+
/* newText(str[, encode]) */
- static int l_newText(lua_State* L)
+ LUA_IMPLEMENT int l_newText(lua_State* L)
{
Encode encode = Encode::UTF8;
if (luax_gettop(L) == 2)
@@ -661,20 +693,48 @@ namespace JinEngine
unsigned length;
const char* data = luax_checklstring(L, 1, &length);
Text* text = new Text(encode, data, length);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXT, sizeof(Proxy));
- proxy->bind(new Ref<Text>(text, JIN_GRAPHICS_TEXT));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Text);
+ proxy->bind(new Shared<Text>(text, Jin_Lua_Text));
return 1;
}
+ LUA_IMPLEMENT int l_newSprite(lua_State* L)
+ {
+ Proxy* p = luax_newinstance(L, Jin_Lua_Sprite);
+ p->bind(new Shared<Sprite>(new Sprite(), Jin_Lua_Sprite));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_newSpriteSheet(lua_State* L)
+ {
+ Proxy* pxyGraphic = nullptr;
+ if (luax_istype(L, 1, Jin_Lua_Texture))
+ pxyGraphic = (Proxy*)luax_checktype(L, 1, Jin_Lua_Texture);
+ else if(luax_istype(L, 1, Jin_Lua_Canvas))
+ pxyGraphic = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ if (pxyGraphic != nullptr)
+ {
+ Proxy* pxySSheet = luax_newinstance(L, Jin_Lua_SpriteSheet);
+ Graphic* graphic = pxyGraphic->getObject<Graphic>();
+ Shared<SpriteSheet>* shrSSheet = new Shared<SpriteSheet>(new SpriteSheet(graphic), Jin_Lua_SpriteSheet);
+ Shared<Graphic>& shrGraphic = pxyGraphic->getShared<Graphic>();
+ shrSSheet->setDependency((int)SpriteSheetDependency::DEP_GRAPHIC, &shrGraphic);
+ pxySSheet->bind(shrSSheet);
+ return 1;
+ }
+ else
+ return 0;
+ }
+
/* newTextureFont(bitmap, text, color | cellw, cellh) */
- static int l_newTextureFont(lua_State* L)
+ LUA_IMPLEMENT int l_newTextureFont(lua_State* L)
{
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Bitmap);
Bitmap* bitmap = p->getObject<Bitmap>();
Text* text;
- if (luax_istype(L, 2, JIN_GRAPHICS_TEXT))
+ if (luax_istype(L, 2, Jin_Lua_Text))
{
- Proxy* pt = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT);
+ Proxy* pt = (Proxy*)luax_checktype(L, 2, Jin_Lua_Text);
text = pt->getObject<Text>();
}
else if (luax_isstring(L, 2))
@@ -713,92 +773,78 @@ namespace JinEngine
// Delete temporary text.
delete text;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTUREFONT, sizeof(Proxy));
- proxy->bind(new Ref<TextureFont>(textureFont, JIN_GRAPHICS_TEXTUREFONT));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_TextureFont);
+ proxy->bind(new Shared<TextureFont>(textureFont, Jin_Lua_TextureFont));
return 1;
}
/* setFont(font) */
- static int l_setFont(lua_State* L)
+ LUA_IMPLEMENT int l_setFont(lua_State* L)
{
- if (luax_istype(L, 1, JIN_GRAPHICS_TTF))
+ if (luax_istype(L, 1, Jin_Lua_TTF))
{
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF);
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTF);
TTF* ttf = p->getObject<TTF>();
context.curFont = ttf;
}
- else if (luax_istype(L, 1, JIN_GRAPHICS_TEXTUREFONT))
+ else if (luax_istype(L, 1, Jin_Lua_TextureFont))
{
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTUREFONT);
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_TextureFont);
TextureFont* tf = p->getObject<TextureFont>();
context.curFont = tf;
}
return 0;
}
- static int l_unsetFont(lua_State* L)
+ LUA_IMPLEMENT int l_unsetFont(lua_State* L)
{
context.curFont = context.defaultFont;
return 0;
}
- static const luaL_Reg f[] = {
- /* window */
- { "init", l_init },
- { "setTitle", l_setTitle },
- { "getSize", l_getSize },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "destroy", l_destroy },
- /* creators */
- { "newBitmap", l_newBitmap },
- { "newTexture", l_newTexture },
- { "newShader", l_newShader },
- { "newShaderf", l_newShaderf },
- { "newCanvas", l_newCanvas },
- { "newTTFData", l_newTTFData },
- { "newText", l_newText },
- { "newTextureFont", l_newTextureFont },
- /* render */
- { "setClearColor", l_setClearColor },
- { "clear", l_clear },
- { "draw", l_draw },
- { "print", l_print },
- { "drawq", l_drawq },
- { "setColor", l_setColor },
- { "getColor", l_getColor },
- { "present", l_present },
- /* canvas */
- { "bindCanvas", l_bindCanvas },
- { "unbindCanvas", l_unbindCanvas },
- /* shader */
- { "useShader", l_useShader },
- /* shapes */
- { "point", l_point },
- { "line", l_line },
- { "rect", l_rect },
- { "circle", l_circle },
- { "triangle", l_triangle },
- { "polygon", l_polygon },
- /* font */
- { "setFont", l_setFont },
- { "unsetFont", l_unsetFont },
- { 0, 0 }
- };
-
- extern int luaopen_Texture(lua_State* L);
- extern int luaopen_Text(lua_State* L);
- extern int luaopen_TTF(lua_State* L);
- extern int luaopen_TextureFont(lua_State* L);
- extern int luaopen_TTFData(lua_State* L);
- extern int luaopen_Page(lua_State* L);
- extern int luaopen_Canvas(lua_State* L);
- extern int luaopen_JSL(lua_State* L);
- extern int luaopen_Bitmap(lua_State* L);
-
- int luaopen_graphics(lua_State* L)
+ LUA_IMPLEMENT int l_clearMatrix(lua_State* L)
+ {
+ gl.clearMatrix();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pushMatrix(lua_State* L)
+ {
+ gl.push();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_popMatrix(lua_State* L)
+ {
+ gl.pop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_scale(lua_State* L)
+ {
+ float sx = luax_checknumber(L, 1);
+ float sy = luax_checknumber(L, 2);
+ gl.scale(sx, sy);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_translate(lua_State* L)
+ {
+ float x = luax_checknumber(L, 1);
+ float y = luax_checknumber(L, 2);
+ gl.translate(x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_rotate(lua_State* L)
+ {
+ float r = luax_checknumber(L, 1);
+ gl.rotate(r);
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_graphics(lua_State* L)
{
- // register types
luaopen_Bitmap(L);
luaopen_Texture(L);
luaopen_Canvas(L);
@@ -807,13 +853,70 @@ namespace JinEngine
luaopen_Text(L);
luaopen_TextureFont(L);
luaopen_Page(L);
- luaopen_JSL(L);
-
- // load whole lib
+ luaopen_Shader(L);
+ luaopen_Sprite(L);
+ luaopen_SpriteSheet(L);
+
+ luaL_Reg f[] = {
+ /* window */
+ { "init", l_init },
+ { "setTitle", l_setTitle },
+ { "getSize", l_getSize },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "destroy", l_destroy },
+ { "hideWindow", l_hideWindow },
+ { "showWindow", l_showWindow },
+ /* creators */
+ { "newBitmap", l_newBitmap },
+ { "newTexture", l_newTexture },
+ { "newShader", l_newShader },
+ { "newShaderf", l_newShaderf },
+ { "newCanvas", l_newCanvas },
+ { "newTTFData", l_newTTFData },
+ { "newText", l_newText },
+ { "newTextureFont", l_newTextureFont },
+ { "newSprite", l_newSprite },
+ { "newSpriteSheet", l_newSpriteSheet },
+ /* render */
+ { "setClearColor", l_setClearColor },
+ { "clear", l_clear },
+ { "draw", l_draw },
+ { "print", l_print },
+ { "drawq", l_drawq },
+ { "setColor", l_setColor },
+ { "getColor", l_getColor },
+ { "present", l_present },
+ /* canvas */
+ { "bindCanvas", l_bindCanvas },
+ { "unbindCanvas", l_unbindCanvas },
+ /* shader */
+ { "useShader", l_useShader },
+ /* shapes */
+ { "point", l_point },
+ { "line", l_line },
+ { "rect", l_rect },
+ { "circle", l_circle },
+ { "triangle", l_triangle },
+ { "polygon", l_polygon },
+ /* font */
+ { "setFont", l_setFont },
+ { "unsetFont", l_unsetFont },
+ /* transform */
+ { "pushMatrix", l_pushMatrix },
+ { "clearMatrix", l_clearMatrix },
+ { "popMatrix", l_popMatrix },
+ { "translate", l_translate },
+ { "rotate", l_rotate },
+ { "scale", l_scale },
+ { 0, 0 }
+ };
+
+ // Load whole lib.
luax_newlib(L, f);
return 1;
}
- }// lua
-}// jin \ No newline at end of file
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_graphics.h b/src/lua/modules/graphics/je_lua_graphics.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_graphics.h
diff --git a/src/lua/modules/graphics/je_lua_page.cpp b/src/lua/modules/graphics/je_lua_page.cpp
new file mode 100644
index 0000000..20ec398
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_page.cpp
@@ -0,0 +1,69 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include <iostream>
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Fonts;
+using namespace JinEngine::Graphics::Shaders;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Page = "Page";
+
+ typedef Shared<Font>& SharedFont;
+
+ Page* getPage(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Page);
+ return proxy->getObject<Page>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Page);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ Page* page = getPage(L);
+ luax_pushinteger(L, page->size.w);
+ luax_pushinteger(L, page->size.h);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ Page* page = getPage(L);
+ luax_pushinteger(L, page->size.w);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
+ {
+ Page* page = getPage(L);
+ luax_pushinteger(L, page->size.h);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_Page(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getSize", l_getSize },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Page, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_page.h b/src/lua/modules/graphics/je_lua_page.h
new file mode 100644
index 0000000..e4a21a3
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_page.h
@@ -0,0 +1,22 @@
+#ifndef __JE_LUA_PAGE_H__
+#define __JE_LUA_PAGE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ enum class PageDependency
+ {
+ DEP_TTF = 1,
+ DEP_TEXTURE_FONT = 2,
+ };
+
+ extern const char* Jin_Lua_Page;
+
+ void luaopen_Page(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_particle_system.cpp b/src/lua/modules/graphics/je_lua_particle_system.cpp
new file mode 100644
index 0000000..7099a5c
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_particle_system.cpp
@@ -0,0 +1,11 @@
+#include "libjin/jin.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+
+
+ } // Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_particle_system.h b/src/lua/modules/graphics/je_lua_particle_system.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_particle_system.h
diff --git a/src/lua/modules/graphics/je_lua_shader.cpp b/src/lua/modules/graphics/je_lua_shader.cpp
new file mode 100644
index 0000000..1612a69
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_shader.cpp
@@ -0,0 +1,137 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_shader.h"
+#include "je_lua_canvas.h"
+#include "je_lua_texture.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Shaders;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Shader = "Shader";
+
+ typedef Shared<Shader>& ShaderRef;
+
+ static inline ShaderRef checkShader(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Shader);
+ return proxy->getShared<Shader>();
+ }
+
+ /**
+ * jsl:sendNumber("variable", 0.1)
+ */
+ LUA_IMPLEMENT int l_sendNumber(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ float number = luax_checknumber(L, 3);
+ shared->sendFloat(variable, number);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendTexture(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 3, Jin_Lua_Texture);
+ Shared<Texture>& tex = proxy->getShared<Texture>();
+ shared->sendTexture(variable, tex.getObject());
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendCanvas(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 3, Jin_Lua_Canvas);
+ Shared<Canvas>& canvas = proxy->getShared<Canvas>();
+ shared->sendCanvas(variable, canvas.getObject());
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendVec2(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ if (!luax_istable(L, 3))
+ {
+ luax_typerror(L, 3, "table");
+ return 1;
+ }
+ float x = luax_rawgetnumber(L, 3, 1);
+ float y = luax_rawgetnumber(L, 3, 2);
+ shared->sendVec2(variable, x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendVec3(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ if (!luax_istable(L, 3))
+ {
+ luax_typerror(L, 3, "table");
+ return 1;
+ }
+ float x = luax_rawgetnumber(L, 3, 1);
+ float y = luax_rawgetnumber(L, 3, 2);
+ float z = luax_rawgetnumber(L, 3, 3);
+ shared->sendVec3(variable, x, y, z);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendVec4(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ if (!luax_istable(L, 3))
+ {
+ luax_typerror(L, 3, "table");
+ return 1;
+ }
+ float x = luax_rawgetnumber(L, 3, 1);
+ float y = luax_rawgetnumber(L, 3, 2);
+ float z = luax_rawgetnumber(L, 3, 3);
+ float w = luax_rawgetnumber(L, 3, 4);
+ shared->sendVec4(variable, x, y, z, w);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendColor(lua_State* L)
+ {
+ return l_sendVec4(L);
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Shader);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Shader(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "sendNumber", l_sendNumber },
+ { "sendTexture", l_sendTexture },
+ { "sendCanvas", l_sendCanvas },
+ { "sendVec2", l_sendVec2 },
+ { "sendVec3", l_sendVec3 },
+ { "sendVec4", l_sendVec4 },
+ { "sendColor", l_sendColor },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Shader, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_shader.h b/src/lua/modules/graphics/je_lua_shader.h
new file mode 100644
index 0000000..5a84372
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_shader.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_SHDER_H__
+#define __JE_LUA_SHDER_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Shader;
+
+ void luaopen_Shader(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_sprite.cpp b/src/lua/modules/graphics/je_lua_sprite.cpp
new file mode 100644
index 0000000..97128a9
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_sprite.cpp
@@ -0,0 +1,262 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_sprite.h"
+#include "je_lua_canvas.h"
+#include "je_lua_texture.h"
+#include "je_lua_shader.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Shaders;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+ const char* Jin_Lua_Sprite = "Sprite";
+
+ typedef Shared<Sprite>& SharedSprite;
+
+ LUA_IMPLEMENT inline SharedSprite checkSprite(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ return proxy->getShared<Sprite>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ p->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setRotation(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float r = luax_checknumber(L, 2);
+ sprite->setRotation(r);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setOrigin(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ switch (luax_gettop(L))
+ {
+ case 2:
+ {
+ int origin = luax_checkinteger(L, 2);
+ sprite->setOrigin(static_cast<Sprite::Origin>(origin));
+ }
+ break;
+ case 3:
+ {
+ int x = luax_checkinteger(L, 2);
+ int y = luax_checkinteger(L, 3);
+ sprite->setOrigin(x, y);
+ }
+ break;
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setPosition(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
+ sprite->setPosition(x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setScale(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float sx = luax_checknumber(L, 2);
+ float sy = luax_checknumber(L, 3);
+ sprite->setScale(sx, sy);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setColor(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ Channel r = luax_checkinteger(L, 2);
+ Channel g = luax_checkinteger(L, 3);
+ Channel b = luax_checkinteger(L, 4);
+ Channel a = luax_checkinteger(L, 5);
+ sprite->setColor(Color(r, g, b, a));
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setShader(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 2, Jin_Lua_Shader);
+ Shader* shader = proxy->getObject<Shader>();
+ sprite->setShader(shader);
+ sprite.setDependency((int)SpriteDependency::DEP_SHADER, &proxy->getShared<Shader>());
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setGraphic(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ Graphic* graphic = nullptr;
+ Proxy* p = nullptr;
+ if (luax_istype(L, 2, Jin_Lua_Texture))
+ p = (Proxy*)luax_checktype(L, 2, Jin_Lua_Texture);
+ else if (luax_istype(L, 2, Jin_Lua_Canvas))
+ p = (Proxy*)luax_checktype(L, 2, Jin_Lua_Canvas);
+ if (p != nullptr)
+ {
+ sprite->setGraphic(p->getObject<Graphic>());
+ sprite.setDependency((int)SpriteDependency::DEP_GRAPHIC, &p->getShared<Graphic>());
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_move(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
+ sprite->move(x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_scale(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float sx = luax_checknumber(L, 2);
+ float sy = luax_checknumber(L, 3);
+ sprite->scale(sx, sy);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_rotate(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float r = luax_checknumber(L, 2);
+ sprite->rotate(r);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getRotation(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float r = sprite->getRotation();
+ luax_pushnumber(L, r);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getPosition(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ const Math::Vector2<float>& pos = sprite->getPosition();
+ luax_pushnumber(L, pos.x);
+ luax_pushnumber(L, pos.y);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getOrigin(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ const Math::Vector2<int>& origin = sprite->getOrigin();
+ luax_pushinteger(L, origin.x);
+ luax_pushinteger(L, origin.y);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getScale(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ const Math::Vector2<float> scale = sprite->getScale();
+ luax_pushnumber(L, scale.x);
+ luax_pushnumber(L, scale.y);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getColor(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ const Color& c = sprite->getColor();
+ luax_pushinteger(L, c.r);
+ luax_pushinteger(L, c.g);
+ luax_pushinteger(L, c.b);
+ luax_pushinteger(L, c.a);
+ return 4;
+ }
+
+ LUA_IMPLEMENT int l_render(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ sprite->render();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getGraphic(lua_State* L)
+ {
+ Proxy* pxySprite = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ Shared<Sprite>& shrSprite = pxySprite->getShared<Sprite>();
+ SharedBase* shrGraphic = shrSprite.getDependency((int)SpriteDependency::DEP_GRAPHIC);
+ if (shrGraphic->isType(Jin_Lua_Canvas))
+ {
+ Proxy* pxyCanvas = luax_newinstance(L, Jin_Lua_Canvas);
+ pxyCanvas->bind(shrGraphic);
+ return 1;
+ }
+ else if (shrGraphic->isType(Jin_Lua_Texture))
+ {
+ Proxy* pxyTexture = luax_newinstance(L, Jin_Lua_Texture);
+ pxyTexture->bind(shrGraphic);
+ return 1;
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getShader(lua_State* L)
+ {
+ Proxy* pxySprite = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ Shared<Sprite>& shrSprite = pxySprite->getShared<Sprite>();
+ SharedBase* shrShader = shrSprite.getDependency((int)SpriteDependency::DEP_SHADER);
+ if (shrShader != nullptr && shrShader->isType(Jin_Lua_Shader))
+ {
+ Proxy* pxyShader = luax_newinstance(L, Jin_Lua_Shader);
+ pxyShader->bind(shrShader);
+ return 1;
+ }
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Sprite(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "render", l_render },
+ { "setRotation", l_setRotation },
+ { "setOrigin", l_setOrigin },
+ { "setPosition", l_setPosition },
+ { "setScale", l_setScale },
+ { "setColor", l_setColor },
+ { "setShader", l_setShader },
+ { "setGraphic", l_setGraphic },
+ { "move", l_move },
+ { "scale", l_scale },
+ { "rotate", l_rotate },
+ { "getRotation", l_getRotation },
+ { "getPosition", l_getPosition },
+ { "getOrigin", l_getOrigin },
+ { "getScale", l_getScale },
+ { "getColor", l_getColor },
+ { "getShader", l_getShader },
+ { "getGraphic", l_getGraphic },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Sprite, methods);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_sprite.h b/src/lua/modules/graphics/je_lua_sprite.h
new file mode 100644
index 0000000..02c44bf
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_sprite.h
@@ -0,0 +1,24 @@
+#ifndef __JE_LUA_SPRITE_H__
+#define __JE_LUA_SPRITE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ // Sprite dependency slots.
+ enum class SpriteDependency
+ {
+ DEP_GRAPHIC = 1,
+ DEP_SHADER = 2,
+ DEP_SPRITESHEET = 3
+ };
+
+ extern const char* Jin_Lua_Sprite;
+
+ void luaopen_Sprite(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_spritesheet.cpp b/src/lua/modules/graphics/je_lua_spritesheet.cpp
new file mode 100644
index 0000000..15469e9
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_spritesheet.cpp
@@ -0,0 +1,54 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_sprite.h"
+#include "je_lua_spritesheet.h"
+
+using namespace JinEngine::Math;
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_SpriteSheet = "SpriteSheet";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* pxySSheet = (Proxy*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
+ pxySSheet->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newSprite(lua_State* L)
+ {
+ Proxy* pxySSheet = (Proxy*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
+ Shared<SpriteSheet>& shrSSheet = pxySSheet->getShared<SpriteSheet>();
+ SpriteSheet* sheet = pxySSheet->getObject<SpriteSheet>();
+ Quad quad;
+ quad.x = luax_checkinteger(L, 2);
+ quad.y = luax_checkinteger(L, 3);
+ quad.w = luax_checkinteger(L, 4);
+ quad.h = luax_checkinteger(L, 5);
+ Sprite* spr = sheet->createSprite(quad);
+ Proxy* pxySprite = luax_newinstance(L, Jin_Lua_Sprite);
+ Shared<Sprite>* shrSprite = new Shared<Sprite>(spr, Jin_Lua_Sprite);
+ shrSprite->setDependency((int)SpriteDependency::DEP_SPRITESHEET, &shrSSheet);
+ pxySprite->bind(shrSprite);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_SpriteSheet(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "newSprite", l_newSprite },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_SpriteSheet, methods);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_spritesheet.h b/src/lua/modules/graphics/je_lua_spritesheet.h
new file mode 100644
index 0000000..bcae60b
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_spritesheet.h
@@ -0,0 +1,21 @@
+#ifndef __JE_LUA_SPRITE_SHEET_H__
+#define __JE_LUA_SPRITE_SHEET_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ enum class SpriteSheetDependency
+ {
+ DEP_GRAPHIC = 1
+ };
+
+ extern const char* Jin_Lua_SpriteSheet;
+
+ void luaopen_SpriteSheet(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_text.cpp b/src/lua/modules/graphics/je_lua_text.cpp
new file mode 100644
index 0000000..9377a0a
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_text.cpp
@@ -0,0 +1,32 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Text = "Text";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Text);
+ p->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Text(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Text, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_text.h b/src/lua/modules/graphics/je_lua_text.h
new file mode 100644
index 0000000..dfcc9cc
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_text.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_TEXT_H__
+#define __JE_LUA_TEXT_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Text;
+
+ void luaopen_Text(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture.cpp b/src/lua/modules/graphics/je_lua_texture.cpp
new file mode 100644
index 0000000..79ddc63
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_texture.cpp
@@ -0,0 +1,66 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_texture.h"
+
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Texture = "Texture";
+
+ typedef Shared<Texture>& SharedTexture;
+
+ LUA_IMPLEMENT inline SharedTexture checkTexture(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Texture);
+ return proxy->getShared<Texture>();
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ SharedTexture shared = checkTexture(L);
+ luax_pushnumber(L, shared->getWidth());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State *L)
+ {
+ SharedTexture shared = checkTexture(L);
+ luax_pushnumber(L, shared->getHeight());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ SharedTexture shared = checkTexture(L);
+ luax_pushnumber(L, shared->getWidth());
+ luax_pushnumber(L, shared->getHeight());
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Texture);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Texture(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Texture, f);
+ }
+
+ }// namespace Lua
+}// namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture.h b/src/lua/modules/graphics/je_lua_texture.h
new file mode 100644
index 0000000..c8bb71c
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_texture.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_TEXTURE_H__
+#define __JE_LUA_TEXTURE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Texture;
+
+ void luaopen_Texture(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp
new file mode 100644
index 0000000..8ca3ce5
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_texture_font.cpp
@@ -0,0 +1,66 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_page.h"
+#include "je_lua_text.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Fonts;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_TextureFont = "TextureFont";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_TextureFont);
+ proxy->release();
+ return 0;
+ }
+
+ /* typeset(Text | string, lineheight, spacing) */
+ LUA_IMPLEMENT int l_typeset(lua_State* L)
+ {
+ Proxy* pxyTexFont = (Proxy*)luax_checktype(L, 1, Jin_Lua_TextureFont);
+ Shared<TextureFont>& shrTexFont = pxyTexFont->getShared<TextureFont>();
+ TextureFont* tf = pxyTexFont->getObject<TextureFont>();
+ int lineheight = luax_checkinteger(L, 3);
+ int spacing = luax_optnumber(L, 4, 0);
+ Page* page = nullptr;
+ if (luax_isstring(L, 2))
+ {
+ unsigned length;
+ const char* str = luax_checklstring(L, 2, &length);
+ Text text(Encode::UTF8, str, length);
+ page = tf->typeset(text, lineheight, spacing);
+ }
+ else if (luax_istype(L, 2, Jin_Lua_Text))
+ {
+ Proxy* p2 = (Proxy*)luax_checktype(L, 2, Jin_Lua_Text);
+ Text* text = p2->getObject<Text>();
+ page = tf->typeset(*text, lineheight, spacing);
+ }
+ Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page);
+ Shared<Page>* shrPage = new Shared<Page>(page, Jin_Lua_Page);
+ shrPage->setDependency((int)PageDependency::DEP_TEXTURE_FONT, &shrTexFont);
+ pxyPage->bind(shrPage);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_TextureFont(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "typeset", l_typeset },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TextureFont, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture_font.h b/src/lua/modules/graphics/je_lua_texture_font.h
new file mode 100644
index 0000000..d1fffe5
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_texture_font.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_TEXTURE_FONT_H__
+#define __JE_LUA_TEXTURE_FONT_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_TextureFont;
+
+ void luaopen_TextureFont(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp
new file mode 100644
index 0000000..c5d922b
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_ttf.cpp
@@ -0,0 +1,66 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_page.h"
+#include "je_lua_text.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Fonts;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_TTF = "TTF";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTF);
+ proxy->release();
+ return 0;
+ }
+
+ /* typeset(Text | string, lineheight, spacing) */
+ LUA_IMPLEMENT int l_typeset(lua_State* L)
+ {
+ Proxy* pxyTTF = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTF);
+ Shared<TTF>& shrTTF = pxyTTF->getShared<TTF>();
+ TTF* ttf = pxyTTF->getObject<TTF>();
+ int lineheight = luax_optnumber(L, 3, ttf->getFontSize());
+ int spacing = luax_optnumber(L, 4, 0);
+ Page* page = nullptr;
+ if (luax_isstring(L, 2))
+ {
+ unsigned length;
+ const char* str = luax_checklstring(L, 2, &length);
+ Text text(Encode::UTF8, str, length);
+ page = ttf->typeset(text, lineheight, spacing);
+ }
+ else if (luax_istype(L, 2, Jin_Lua_Text))
+ {
+ Proxy* pxyText = (Proxy*)luax_checktype(L, 2, Jin_Lua_Text);
+ Text* text = pxyText->getObject<Text>();
+ page = ttf->typeset(*text, lineheight, spacing);
+ }
+ Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page);
+ Shared<Page>* refPage = new Shared<Page>(page, Jin_Lua_Page);
+ refPage->setDependency((int)PageDependency::DEP_TTF, &shrTTF);
+ pxyPage->bind(refPage);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_TTF(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "typeset", l_typeset },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TTF, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf.h b/src/lua/modules/graphics/je_lua_ttf.h
new file mode 100644
index 0000000..bfe503d
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_ttf.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_TTF_H__
+#define __JE_LUA_TTF_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_TTF;
+
+ void luaopen_TTF(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf_data.cpp b/src/lua/modules/graphics/je_lua_ttf_data.cpp
new file mode 100644
index 0000000..1277318
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_ttf_data.cpp
@@ -0,0 +1,52 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_ttf.h"
+#include "je_lua_ttf_data.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Fonts;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_TTFData = "TTFData";
+
+ LUA_IMPLEMENT int l_newTTF(lua_State* L)
+ {
+ Proxy* pxyTTFData = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTFData);
+ int fontsize = luax_checkinteger(L, 2);
+ Shared<TTFData>& shrFontData = pxyTTFData->getShared<TTFData>();
+ TTFData* fontData = shrFontData.getObject();
+ Proxy* pxyTTF = luax_newinstance(L, Jin_Lua_TTF);
+ TTF* font = fontData->createTTF(fontsize);
+ Shared<TTF>* shrTTF = new Shared<TTF>(font, Jin_Lua_TTF);
+ shrTTF->setDependency((int)TTFDependency::DEP_TTFDATA, &shrFontData);
+ pxyTTF->bind(shrTTF);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTFData);
+ p->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_TTFData(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "newTTF", l_newTTF },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TTFData, f);
+
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf_data.h b/src/lua/modules/graphics/je_lua_ttf_data.h
new file mode 100644
index 0000000..1fd832d
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_ttf_data.h
@@ -0,0 +1,21 @@
+#ifndef __JE_LUA_TTFDATA_H__
+#define __JE_LUA_TTFDATA_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ enum class TTFDependency
+ {
+ DEP_TTFDATA = 1,
+ };
+
+ extern const char* Jin_Lua_TTFData;
+
+ void luaopen_TTFData(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/page.cpp b/src/lua/modules/graphics/page.cpp
deleted file mode 100644
index 8c9e918..0000000
--- a/src/lua/modules/graphics/page.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-#include <iostream>
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Font>& FontRef;
-
- Page* getPage(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_PAGE);
- return proxy->getObject<Page>();
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_PAGE);
- {
- /* release font */
- Ref<Page>* page = &proxy->getRef<Page>();
- RefBase* font = (RefBase*)page->getUserdata();
- font->release();
- }
- proxy->release();
- return 0;
- }
-
- static int l_getSize(lua_State* L)
- {
- Page* page = getPage(L);
- luax_pushinteger(L, page->size.w);
- luax_pushinteger(L, page->size.h);
- return 2;
- }
-
- static int l_getWidth(lua_State* L)
- {
- Page* page = getPage(L);
- luax_pushinteger(L, page->size.w);
- return 1;
- }
-
- static int l_getHeight(lua_State* L)
- {
- Page* page = getPage(L);
- luax_pushinteger(L, page->size.h);
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getSize", l_getSize },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { 0, 0 }
- };
-
- int luaopen_Page(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_PAGE, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/shader.cpp b/src/lua/modules/graphics/shader.cpp
deleted file mode 100644
index d7733d4..0000000
--- a/src/lua/modules/graphics/shader.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Shader>& ShaderRef;
-
- static inline ShaderRef checkShader(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SHADER);
- return proxy->getRef<Shader>();
- }
-
- /**
- * jsl:sendNumber("variable", 0.1)
- */
- static int l_sendNumber (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- float number = luax_checknumber(L, 3);
- ref->sendFloat(variable, number);
- return 0;
- }
-
- static int l_sendTexture (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_TEXTURE);
- Ref<Texture>& tex = proxy->getRef<Texture>();
- ref->sendTexture(variable, tex.getObject());
- return 0;
- }
-
- static int l_sendCanvas (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_CANVAS);
- Ref<Canvas>& canvas = proxy->getRef<Canvas>();
- ref->sendCanvas(variable, canvas.getObject());
- return 0;
- }
-
- static int l_sendVec2 (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- if (!luax_istable(L, 3))
- {
- luax_typerror(L, 3, "table");
- return 1;
- }
- float x = luax_rawgetnumber(L, 3, 1);
- float y = luax_rawgetnumber(L, 3, 2);
- ref->sendVec2(variable, x, y);
- return 0;
- }
-
- static int l_sendVec3 (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- if (!luax_istable(L, 3))
- {
- luax_typerror(L, 3, "table");
- return 1;
- }
- float x = luax_rawgetnumber(L, 3, 1);
- float y = luax_rawgetnumber(L, 3, 2);
- float z = luax_rawgetnumber(L, 3, 3);
- ref->sendVec3(variable, x, y, z);
- return 0;
- }
-
- static int l_sendVec4 (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- if (!luax_istable(L, 3))
- {
- luax_typerror(L, 3, "table");
- return 1;
- }
- float x = luax_rawgetnumber(L, 3, 1);
- float y = luax_rawgetnumber(L, 3, 2);
- float z = luax_rawgetnumber(L, 3, 3);
- float w = luax_rawgetnumber(L, 3, 4);
- ref->sendVec4(variable, x, y, z, w);
- return 0;
- }
-
- static int l_sendColor (lua_State* L)
- {
- return l_sendVec4(L);
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SHADER);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "sendNumber", l_sendNumber },
- { "sendTexture", l_sendTexture },
- { "sendCanvas", l_sendCanvas },
- { "sendVec2", l_sendVec2 },
- { "sendVec3", l_sendVec3 },
- { "sendVec4", l_sendVec4 },
- { "sendColor", l_sendColor },
- { 0, 0 }
- };
-
- /**
- * JSL program
- */
- int luaopen_JSL(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_SHADER, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/text.cpp b/src/lua/modules/graphics/text.cpp
deleted file mode 100644
index cbc82f1..0000000
--- a/src/lua/modules/graphics/text.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- static int l_gc(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXT);
- p->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { 0, 0 }
- };
-
- int luaopen_Text(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TEXT, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/texture.cpp b/src/lua/modules/graphics/texture.cpp
deleted file mode 100644
index 61bfaee..0000000
--- a/src/lua/modules/graphics/texture.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Texture>& TextureRef;
-
- static inline TextureRef checkTexture(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTURE);
- return proxy->getRef<Texture>();
- }
-
- static int l_getWidth(lua_State* L)
- {
- TextureRef ref = checkTexture(L);
- luax_pushnumber(L, ref->getWidth());
- return 1;
- }
-
- static int l_getHeight(lua_State *L)
- {
- TextureRef ref = checkTexture(L);
- luax_pushnumber(L, ref->getHeight());
- return 1;
- }
-
- static int l_getSize(lua_State* L)
- {
- TextureRef ref = checkTexture(L);
- luax_pushnumber(L, ref->getWidth());
- luax_pushnumber(L, ref->getHeight());
- return 2;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTURE);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { 0, 0 }
- };
-
- int luaopen_Texture(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TEXTURE, f);
- return 0;
- }
-
- }// lua
-}// jin \ No newline at end of file
diff --git a/src/lua/modules/graphics/texture_font.cpp b/src/lua/modules/graphics/texture_font.cpp
deleted file mode 100644
index a2e88ba..0000000
--- a/src/lua/modules/graphics/texture_font.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTUREFONT);
- proxy->release();
- return 0;
- }
-
- /* typeset(Text | string, lineheight, spacing) */
- static int l_typeset(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTUREFONT);
- TextureFont* tf = p->getObject<TextureFont>();
- int lineheight = luax_checkinteger(L, 3);
- int spacing = luax_optnumber(L, 4, 0);
- Page* page = nullptr;
- if (luax_isstring(L, 2))
- {
- unsigned length;
- const char* str = luax_checklstring(L, 2, &length);
- Text text(Encode::UTF8, str, length);
- page = tf->typeset(text, lineheight, spacing);
- }
- else if (luax_istype(L, 2, JIN_GRAPHICS_TEXT))
- {
- Proxy* p2 = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT);
- Text* text = p2->getObject<Text>();
- page = tf->typeset(*text, lineheight, spacing);
- }
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_PAGE, sizeof(Proxy));
- Ref<Page>* refPage = new Ref<Page>(page, JIN_GRAPHICS_PAGE);
- {
- /* retain related ttf */
- Ref<TextureFont>& refTF = p->getRef<TextureFont>();
- refTF.retain();
- refPage->setUserdata(&refTF);
- }
- proxy->bind(refPage);
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "typeset", l_typeset },
- { 0, 0 }
- };
-
- int luaopen_TextureFont(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TEXTUREFONT, f);
-
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/ttf.cpp b/src/lua/modules/graphics/ttf.cpp
deleted file mode 100644
index 414c7eb..0000000
--- a/src/lua/modules/graphics/ttf.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF);
- {
- /* release ttf data */
- Ref<TTF>* ttf = &proxy->getRef<TTF>();
- RefBase* data = (RefBase*)ttf->getUserdata();
- data->release();
- }
- proxy->release();
- return 0;
- }
-
- /* typeset(Text | string, lineheight, spacing) */
- static int l_typeset(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF);
- TTF* ttf = p->getObject<TTF>();
- int lineheight = luax_optnumber(L, 3, ttf->getFontSize());
- int spacing = luax_optnumber(L, 4, 0);
- Page* page = nullptr;
- if (luax_isstring(L, 2))
- {
- unsigned length;
- const char* str = luax_checklstring(L, 2, &length);
- Text text(Encode::UTF8, str, length);
- page = ttf->typeset(text, lineheight, spacing);
- }
- else if (luax_istype(L, 2, JIN_GRAPHICS_TEXT))
- {
- Proxy* p2 = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT);
- Text* text = p2->getObject<Text>();
- page = ttf->typeset(*text, lineheight, spacing);
- }
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_PAGE, sizeof(Proxy));
- Ref<Page>* refPage = new Ref<Page>(page, JIN_GRAPHICS_PAGE);
- {
- /* retain related ttf */
- Ref<TTF>& refTTF = p->getRef<TTF>();
- refTTF.retain();
- refPage->setUserdata(&refTTF);
- }
- proxy->bind(refPage);
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "typeset", l_typeset },
- { 0, 0 }
- };
-
- int luaopen_TTF(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TTF, f);
-
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/ttfData.cpp b/src/lua/modules/graphics/ttfData.cpp
deleted file mode 100644
index 43c3613..0000000
--- a/src/lua/modules/graphics/ttfData.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- static int l_newTTF(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTFDATA);
- int fontsize = luax_checkinteger(L, 2);
- Ref<TTFData>& refFontData = p->getRef<TTFData>();
- TTFData* fontData = refFontData.getObject();
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TTF, sizeof(Proxy));
- TTF* font = fontData->createTTF(fontsize);
- Ref<TTF>* refTTF = new Ref<TTF>(font, JIN_GRAPHICS_TTF);
- {
- Ref<TTFData>& refTTFData = p->getRef<TTFData>();
- refTTFData.retain();
- refTTF->setUserdata(&refTTFData);
- }
- proxy->bind(refTTF);
- return 1;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTFDATA);
- p->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "newTTF", l_newTTF },
- { 0, 0 }
- };
-
- int luaopen_TTFData(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TTFDATA, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/joypad/joypad.cpp b/src/lua/modules/joypad/je_lua_joypad.cpp
index d67a624..a57fc99 100644
--- a/src/lua/modules/joypad/joypad.cpp
+++ b/src/lua/modules/joypad/je_lua_joypad.cpp
@@ -1,17 +1,17 @@
-#include "libjin/jin.h"
#include "lua/modules/luax.h"
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
namespace JinEngine
{
namespace Lua
{
- static const luaL_Reg f[] = {
- { 0, 0 }
- };
-
- int luaopen_joypad(lua_State* L)
+ LUA_EXPORT int luaopen_joypad(lua_State* L)
{
+ luaL_Reg f[] = {
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/joypad/je_lua_joypad.h b/src/lua/modules/joypad/je_lua_joypad.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/joypad/je_lua_joypad.h
diff --git a/src/lua/modules/keyboard/keyboard.cpp b/src/lua/modules/keyboard/je_lua_keyboard.cpp
index 727a51e..6b7f3cd 100644
--- a/src/lua/modules/keyboard/keyboard.cpp
+++ b/src/lua/modules/keyboard/je_lua_keyboard.cpp
@@ -1,3 +1,4 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
namespace JinEngine
@@ -6,7 +7,7 @@ namespace JinEngine
{
//https://wiki.libsdl.org/SDL_Keycode
- int luaopen_keyboard(lua_State* L)
+ LUA_EXPORT int luaopen_keyboard(lua_State* L)
{
luax_newlib(L, 0);
return 1;
diff --git a/src/lua/modules/keyboard/je_lua_keyboard.h b/src/lua/modules/keyboard/je_lua_keyboard.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/keyboard/je_lua_keyboard.h
diff --git a/src/lua/modules/math/math.cpp b/src/lua/modules/math/je_lua_math.cpp
index 4891762..2afeaf9 100644
--- a/src/lua/modules/math/math.cpp
+++ b/src/lua/modules/math/je_lua_math.cpp
@@ -1,3 +1,4 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
@@ -6,7 +7,7 @@ namespace JinEngine
namespace Lua
{
- static int l_mod(lua_State* L)
+ LUA_IMPLEMENT int l_mod(lua_State* L)
{
int n = luax_checkinteger(L, 1);
int m = luax_checkinteger(L, 2);
@@ -15,13 +16,12 @@ namespace JinEngine
return 1;
}
- static const luaL_Reg f[] = {
- { "mod", l_mod },
- { 0, 0 }
- };
-
- int luaopen_math(lua_State* L)
+ LUA_EXPORT int luaopen_math(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "mod", l_mod },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
}
diff --git a/src/lua/modules/math/je_lua_math.h b/src/lua/modules/math/je_lua_math.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/math/je_lua_math.h
diff --git a/src/lua/modules/mouse/mouse.cpp b/src/lua/modules/mouse/je_lua_mouse.cpp
index 9d45178..9e6824a 100644
--- a/src/lua/modules/mouse/mouse.cpp
+++ b/src/lua/modules/mouse/je_lua_mouse.cpp
@@ -1,14 +1,15 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
+using namespace JinEngine::Input;
+
namespace JinEngine
{
namespace Lua
{
- using namespace JinEngine::Input;
-
- static int l_pos(lua_State* L)
+ LUA_IMPLEMENT int l_pos(lua_State* L)
{
static Mouse* mouse = Mouse::get();
int x, y;
@@ -18,22 +19,21 @@ namespace JinEngine
return 2;
}
- static int l_setVisible(lua_State* L)
+ LUA_IMPLEMENT int l_setVisible(lua_State* L)
{
bool visible = luax_checkbool(L, 1);
Mouse* mouse = Mouse::get();
mouse->setVisible(visible);
return 0;
}
-
- static const luaL_Reg f[] = {
- { "position", l_pos },
- { "setVisible", l_setVisible },
- { 0, 0 }
- };
- int luaopen_mouse(lua_State* L)
+ LUA_EXPORT int luaopen_mouse(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "getPosition", l_pos },
+ { "setVisible", l_setVisible },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
}
diff --git a/src/lua/modules/mouse/je_lua_mouse.h b/src/lua/modules/mouse/je_lua_mouse.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/mouse/je_lua_mouse.h
diff --git a/src/lua/modules/net/Buffer.cpp b/src/lua/modules/net/Buffer.cpp
deleted file mode 100644
index ddfbd6b..0000000
--- a/src/lua/modules/net/Buffer.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-#include "Buffer.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
- namespace Net
- {
-
- using namespace JinEngine;
-
- typedef Ref<Buffer>& BufferRef;
-
- static inline BufferRef checkNetBuffer(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER);
- return proxy->getRef<Buffer>();
- }
-
- // net.Buffer:append(value) -> value_length
- static int l_append(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- const int vp = 2;
- if (luax_isintegerstrict(L, vp))
- {
- int n = luax_checkinteger(L, vp);
- int size = sizeof(n);
- ref->append(&n, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else if (luax_isfloatstrict(L, vp))
- {
- float n = luax_checknumber(L, vp);
- int size = sizeof(n);
- ref->append(&n, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else if (luax_isbooleanstrict(L, vp))
- {
- bool n = luax_checkbool(L, vp);
- int size = sizeof(n);
- ref->append(&n, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else if (luax_isstringstrict(L, vp))
- {
- const char* str = luax_checkstring(L, vp);
- int size = strlen(str) + 1;
- ref->append(str, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else
- {
- luax_typerror(L, vp, "number, bool or string");
- return 0;
- }
- }
-
- // net.Buffer:grabString(offset) -> string, length
- static int l_grabString(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- unsigned int len;
- char* data = ref->grabString(&len, offset);
- Array<char> str;
- str.bind(data, len);
- luax_pushstring(L, &str);
- luax_pushinteger(L, str.count());
- return 2;
- }
-
- // net.Buffer:grabInteger(offset) -> integer, length
- static int l_grabInteger(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- int integer = ref->grabInteger(&len, offset);
- luax_pushinteger(L, integer);
- luax_pushinteger(L, len);
- return 2;
- }
-
- static int l_grabFloat(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- float floatv = ref->grabFloat(&len, offset);
- luax_pushnumber(L, floatv);
- luax_pushinteger(L, len);
- return 2;
- }
-
- static int l_grabBoolean(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- bool boolean = ref->grabBoolean(&len, offset);
- luax_pushboolean(L, boolean);
- luax_pushinteger(L, len);
- return 2;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg netbuffer_function[] = {
- { "__gc", l_gc },
- { "append", l_append },
- { "grabString", l_grabString },
- { "grabInteger", l_grabInteger },
- { "grabBoolean", l_grabBoolean },
- { "grabFloat", l_grabFloat },
- { 0, 0 }
- };
-
- } // namespace Net
-
- int luaopen_Buffer(lua_State* L)
- {
- luax_newtype(L, JIN_NETWORK_BUFFER, Net::netbuffer_function);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/net/je_lua_buffer.cpp b/src/lua/modules/net/je_lua_buffer.cpp
new file mode 100644
index 0000000..0198095
--- /dev/null
+++ b/src/lua/modules/net/je_lua_buffer.cpp
@@ -0,0 +1,137 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_buffer.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Buffer = "Buffer";
+
+ typedef Shared<Net::Buffer>& SharedBuffer;
+
+ static inline SharedBuffer checkNetBuffer(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Buffer);
+ return proxy->getShared<Net::Buffer>();
+ }
+
+ // net.Buffer:append(value) -> value_length
+ LUA_IMPLEMENT int l_append(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ const int vp = 2;
+ if (luax_isintegerstrict(L, vp))
+ {
+ int n = luax_checkinteger(L, vp);
+ int size = sizeof(n);
+ shared->append(&n, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else if (luax_isfloatstrict(L, vp))
+ {
+ float n = luax_checknumber(L, vp);
+ int size = sizeof(n);
+ shared->append(&n, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else if (luax_isbooleanstrict(L, vp))
+ {
+ bool n = luax_checkbool(L, vp);
+ int size = sizeof(n);
+ shared->append(&n, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else if (luax_isstringstrict(L, vp))
+ {
+ const char* str = luax_checkstring(L, vp);
+ int size = strlen(str) + 1;
+ shared->append(str, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else
+ {
+ luax_typerror(L, vp, "number, bool or string");
+ return 0;
+ }
+ }
+
+ // net.Buffer:grabString(offset) -> string, length
+ LUA_IMPLEMENT int l_grabString(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ unsigned int len;
+ char* data = shared->grabString(&len, offset);
+ Array<char> str;
+ str.bind(data, len);
+ luax_pushstring(L, &str);
+ luax_pushinteger(L, str.count());
+ return 2;
+ }
+
+ // net.Buffer:grabInteger(offset) -> integer, length
+ LUA_IMPLEMENT int l_grabInteger(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ int integer = shared->grabInteger(&len, offset);
+ luax_pushinteger(L, integer);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_grabFloat(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ float floatv = shared->grabFloat(&len, offset);
+ luax_pushnumber(L, floatv);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_grabBoolean(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ bool boolean = shared->grabBoolean(&len, offset);
+ luax_pushboolean(L, boolean);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Buffer);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Buffer(lua_State* L)
+ {
+ luaL_Reg netbuffer_function[] = {
+ { "__gc", l_gc },
+ { "append", l_append },
+ { "grabString", l_grabString },
+ { "grabInteger", l_grabInteger },
+ { "grabBoolean", l_grabBoolean },
+ { "grabFloat", l_grabFloat },
+ { 0, 0 }
+ };
+
+ luax_newtype(L, Jin_Lua_Buffer, netbuffer_function);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/net/Buffer.h b/src/lua/modules/net/je_lua_buffer.h
index 8733778..d226640 100644
--- a/src/lua/modules/net/Buffer.h
+++ b/src/lua/modules/net/je_lua_buffer.h
@@ -3,12 +3,17 @@
#include <cstring>
#include <cstdlib>
-#include "lua/common/common.h"
+#include "lua/common/je_lua_common.h"
namespace JinEngine
{
namespace Lua
{
+
+ extern const char* Jin_Lua_Buffer;
+
+ void luaopen_Buffer(lua_State* L);
+
namespace Net
{
diff --git a/src/lua/modules/net/net.cpp b/src/lua/modules/net/je_lua_net.cpp
index 4ef9ece..b081733 100644
--- a/src/lua/modules/net/net.cpp
+++ b/src/lua/modules/net/je_lua_net.cpp
@@ -1,8 +1,10 @@
#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
+
#include "libjin/jin.h"
-#include "lua/common/common.h"
-#include "Buffer.h"
+#include "lua/common/je_lua_common.h"
+
+#include "je_lua_buffer.h"
+#include "je_lua_socket.h"
namespace JinEngine
{
@@ -12,13 +14,13 @@ namespace Lua
using namespace JinEngine::Lua::Net;
using namespace JinEngine::Net;
- static int l_initNetwork(lua_State* L)
+ LUA_IMPLEMENT int l_initNetwork(lua_State* L)
{
JinEngine::Net::NetManager::get()->init();
return 1;
}
- static int l_Socket(lua_State* L)
+ LUA_IMPLEMENT int l_Socket(lua_State* L)
{
SocketInformation info = { 0 };
{
@@ -48,35 +50,31 @@ namespace Lua
}
}
Socket* socket = new Socket(info);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy));
- proxy->bind(new Ref<Socket>(socket, JIN_NETWORK_SOCKET));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket);
+ proxy->bind(new Shared<Socket>(socket, Jin_Lua_Socket));
return 1;
}
- static int l_Buffer(lua_State* L)
+ LUA_IMPLEMENT int l_Buffer(lua_State* L)
{
int size = luax_checkinteger(L, 1);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer);
Net::Buffer* buffer = new Net::Buffer(size);
- proxy->bind(new Ref<Buffer>(buffer, JIN_NETWORK_BUFFER));
+ proxy->bind(new Shared<Buffer>(buffer, Jin_Lua_Buffer));
return 1;
}
- static const luaL_Reg f[] = {
- { "init", l_initNetwork },
- { "newSocket", l_Socket },
- { "newBuffer", l_Buffer },
- { 0, 0 }
- };
-
- extern int luaopen_Socket(lua_State* L);
- extern int luaopen_Buffer(lua_State* L);
-
- int luaopen_net(lua_State* L)
+ LUA_EXPORT int luaopen_net(lua_State* L)
{
luaopen_Socket(L);
luaopen_Buffer(L);
-
+
+ luaL_Reg f[] = {
+ { "init", l_initNetwork },
+ { "newSocket", l_Socket },
+ { "newBuffer", l_Buffer },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/net/je_lua_net.h b/src/lua/modules/net/je_lua_net.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/net/je_lua_net.h
diff --git a/src/lua/modules/net/je_lua_socket.cpp b/src/lua/modules/net/je_lua_socket.cpp
new file mode 100644
index 0000000..db170e4
--- /dev/null
+++ b/src/lua/modules/net/je_lua_socket.cpp
@@ -0,0 +1,129 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_buffer.h"
+
+using namespace JinEngine::Net;
+using namespace JinEngine::Lua::Net;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Socket = "Socket";
+
+ typedef Shared<Socket>& SharedSocket;
+
+ const int BUFFER_SIZE = 1024;
+
+ LUA_IMPLEMENT inline SharedSocket checkSocket(lua_State* L, int pos = 1)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, pos, Jin_Lua_Socket);
+ return proxy->getShared<Socket>();
+ }
+
+ LUA_IMPLEMENT inline Shared<Buffer>& checkNetBuffer(lua_State* L, int pos = 1)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, pos, Jin_Lua_Buffer);
+ return proxy->getShared<Buffer>();
+ }
+
+ // return net.Socket
+ LUA_IMPLEMENT int l_accept(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ Socket* client = socket->accept();
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket);
+ proxy->bind(new Shared<Socket>(client, Jin_Lua_Socket));
+ return 1;
+ }
+
+ // return net.Buffer
+ LUA_IMPLEMENT int l_receive(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ char buffer[BUFFER_SIZE] = {0};
+ int size = socket->receive(buffer, BUFFER_SIZE);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer);
+ Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
+ proxy->bind(new Shared<Buffer>(netBuffer, Jin_Lua_Buffer));
+ return 1;
+ }
+
+ // Socket:receiveFrom(address, port)
+ LUA_IMPLEMENT int l_receiveFrom(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ int address = luax_checkinteger(L, 2);
+ int port = luax_checkinteger(L, 3);
+ char buffer[BUFFER_SIZE];
+ int size = socket->receiveFrom(buffer, BUFFER_SIZE, address, port);
+ Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer);
+ proxy->bind(new Shared<Buffer>(netBuffer, Jin_Lua_Buffer));
+ return 1;
+ }
+
+ // Socket:send(net.Buffer) -> data_length
+ LUA_IMPLEMENT int l_send(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ Shared<Buffer>& shared = checkNetBuffer(L, 2);
+ int len = socket->send(shared->buffer, shared->size);
+ luax_pushinteger(L, len);
+ return 1;
+ }
+
+ // Socket:sendTo(address, port, net.Buffer)
+ LUA_IMPLEMENT int l_sendTo(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ int address = luax_checkinteger(L, 2);
+ int port = luax_checkinteger(L, 3);
+ Shared<Buffer>& buffer = checkNetBuffer(L, 4);
+ socket->sendTo(buffer->buffer, buffer->size, address, port);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_close(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ socket->close();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_configBlocking(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ bool blocking = luax_checkbool(L, 2);
+ socket->configureBlocking(blocking);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Socket);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Socket(lua_State* L)
+ {
+ luaL_Reg socket_function[] = {
+ { "__gc", l_gc },
+ { "accept", l_accept },
+ { "receive", l_receive },
+ { "receiveFrom", l_receiveFrom },
+ { "send", l_send },
+ { "sendTo", l_sendTo },
+ { "close", l_close },
+ { "configBlocking", l_configBlocking },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Socket, socket_function);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/net/je_lua_socket.h b/src/lua/modules/net/je_lua_socket.h
new file mode 100644
index 0000000..b33fac6
--- /dev/null
+++ b/src/lua/modules/net/je_lua_socket.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_SOCKET_H__
+#define __JE_LUA_SOCKET_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Socket;
+
+ void luaopen_Socket(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/net/socket.cpp b/src/lua/modules/net/socket.cpp
deleted file mode 100644
index d6de730..0000000
--- a/src/lua/modules/net/socket.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-#include "Buffer.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Net;
- using namespace Lua::Net;
-
- typedef Ref<Socket>& SocketRef;
-
- const int BUFFER_SIZE = 1024;
-
- static inline SocketRef checkSocket(lua_State* L, int pos = 1)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, pos, JIN_NETWORK_SOCKET);
- return proxy->getRef<Socket>();
- }
-
- static inline Ref<Buffer>& checkNetBuffer(lua_State* L, int pos = 1)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, pos, JIN_NETWORK_BUFFER);
- return proxy->getRef<Buffer>();
- }
-
- // return net.Socket
- static int l_accept(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- Socket* client = socket->accept();
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy));
- proxy->bind(new Ref<Socket>(client, JIN_NETWORK_SOCKET));
- return 1;
- }
-
- // return net.Buffer
- static int l_receive(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- char buffer[BUFFER_SIZE] = {0};
- int size = socket->receive(buffer, BUFFER_SIZE);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
- Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
- proxy->bind(new Ref<Buffer>(netBuffer, JIN_NETWORK_BUFFER));
- return 1;
- }
-
- // Socket:receiveFrom(address, port)
- static int l_receiveFrom(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- int address = luax_checkinteger(L, 2);
- int port = luax_checkinteger(L, 3);
- char buffer[BUFFER_SIZE];
- int size = socket->receiveFrom(buffer, BUFFER_SIZE, address, port);
- Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
- proxy->bind(new Ref<Buffer>(netBuffer, JIN_NETWORK_BUFFER));
- return 1;
- }
-
- // Socket:send(net.Buffer) -> data_length
- static int l_send(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- Ref<Buffer>& ref = checkNetBuffer(L, 2);
- int len = socket->send(ref->buffer, ref->size);
- luax_pushinteger(L, len);
- return 1;
- }
-
- // Socket:sendTo(address, port, net.Buffer)
- static int l_sendTo(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- int address = luax_checkinteger(L, 2);
- int port = luax_checkinteger(L, 3);
- Ref<Buffer>& buffer = checkNetBuffer(L, 4);
- socket->sendTo(buffer->buffer, buffer->size, address, port);
- return 0;
- }
-
- static int l_close(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- socket->close();
- return 0;
- }
-
- static int l_configBlocking(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- bool blocking = luax_checkbool(L, 2);
- socket->configureBlocking(blocking);
- return 0;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_SOCKET);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg socket_function[] = {
- { "__gc", l_gc },
- { "accept", l_accept },
- { "receive", l_receive },
- { "receiveFrom", l_receiveFrom },
- { "send", l_send },
- { "sendTo", l_sendTo },
- { "close", l_close },
- { "configBlocking", l_configBlocking },
- { 0, 0 }
- };
-
- int luaopen_Socket(lua_State* L)
- {
- luax_newtype(L, JIN_NETWORK_SOCKET, socket_function);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/thread/Thread.cpp b/src/lua/modules/thread/Thread.cpp
deleted file mode 100644
index e1c5a92..0000000
--- a/src/lua/modules/thread/Thread.cpp
+++ /dev/null
@@ -1,252 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "libjin/jin.h"
-#include "lua/jin.h"
-#include "lua/common/common.h"
-#include "thread.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using thread::Thread;
-
- typedef Ref<Thread>& ThreadRef;
-
- int luaopen_thread(lua_State* L);
-
- static inline ThreadRef checkThread(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_THREAD_THREAD);
- return proxy->getRef<Thread>();
- }
-
- static int threadRunner(void* t)
- {
- ThreadRef ref = *(Ref<Thread>*)t;
- lua_State* L = lua_open();
- luax_openlibs(L);
- luaopen_jin(L);
- luax_getglobal(L, MODULE_NAME);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_THREAD_THREAD, sizeof(Proxy));
- ref.retain();
- proxy->bind(&ref);
- luax_setfield(L, -2, "_curThread");
- luax_dostring(L, ref->code.c_str());
- luax_close(L);
- return 0;
- }
-
- static int l_thread_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_THREAD_THREAD);
- proxy->release();
- return 0;
- }
-
- static int l_start(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- bool result = ref->start(&ref);
- luax_pushboolean(L, result);
- return 1;
- }
-
- static int l_wait(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- ref->wait();
- return 0;
- }
-
- static int l_send(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- int slot = luax_checkinteger(L, 2);
- const int vp = 3;
- if (luax_isnumberstrict(L, vp))
- {
- float real = luax_checknumber(L, vp);
- ref->send(slot, real);
- }
- else if (luax_isbooleanstrict(L, vp))
- {
- bool bol = luax_checkbool(L, vp);
- ref->send(slot, bol);
- }
- else if (luax_isstringstrict(L, vp))
- {
- const char* str = luax_checkstring(L, vp);
- ref->send(slot, str);
- }
- else if (luax_isuserdata(L, vp))
- {
- void* p = luax_touserdata(L, vp);
- ref->send(slot, p);
- }
- else if (luax_islightuserdata(L, vp))
- {
- void* p = luax_tolightuserdata(L, vp);
- ref->send(slot, p);
- }
- return 0;
- }
-
- static int l_receive(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- int slot = luax_checkinteger(L, 2);
- bool result = ref->receive(slot);
- luax_pushboolean(L, result);
- return 1;
- }
-
- static int l_fetch(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- int slot = luax_checkinteger(L, 2);
- Thread::Variant v = ref->fetch(slot);
- switch (v.type)
- {
- case thread::Thread::Variant::INTERGER:
- luax_pushinteger(L, v.integer);
- break;
-
- case thread::Thread::Variant::BOOLEAN:
- luax_pushboolean(L, v.boolean);
- break;
-
- case thread::Thread::Variant::CSTRING:
- luax_pushstring(L, v.cstring);
- break;
-
- case thread::Thread::Variant::REAL:
- luax_pushnumber(L, v.real);
- break;
-
- case thread::Thread::Variant::POINTER:
- Proxy* p = (Proxy*)v.pointer;
- Proxy* proxy = (Proxy*)luax_newinstance(L, p->getObjectType(), sizeof(Proxy));
- p->reference->retain();
- proxy->bind(p->reference);
- break;
-
- }
- return 1;
- }
-
- static int l_demand(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- int slot = luax_checkinteger(L, 2);
- Thread::Variant v = ref->demand(slot);
- switch (v.type)
- {
- case thread::Thread::Variant::INTERGER:
- luax_pushinteger(L, v.integer);
- break;
-
- case thread::Thread::Variant::BOOLEAN:
- luax_pushboolean(L, v.boolean);
- break;
-
- case thread::Thread::Variant::CSTRING:
- luax_pushstring(L, v.cstring);
- break;
-
- case thread::Thread::Variant::REAL:
- luax_pushnumber(L, v.real);
- break;
-
- case thread::Thread::Variant::POINTER:
- Proxy* p = (Proxy*)v.pointer;
- const char* objType = p->getObjectType();
- Proxy* proxy = (Proxy*)luax_newinstance(L, objType, sizeof(Proxy));
- p->reference->retain();
- proxy->bind(p->reference);
- break;
-
- }
- return 1;
- }
-
- static int l_remove(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- int slot = luax_checkinteger(L, 2);
- ref->remove(slot);
- return 0;
- }
-
- static int l_getName(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- const char* name = ref->getName();
- luax_pushstring(L, name);
- return 1;
- }
-
- static int l_isRunning(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- bool running = ref->isRunning();
- luax_pushboolean(L, running);
- return 1;
- }
-
- static const luaL_Reg thread_function[] = {
- { "__gc", l_thread_gc },
- { "start", l_start },
- { "wait", l_wait },
- { "send", l_send },
- { "receive", l_receive },
- { "fetch", l_fetch },
- { "demand", l_demand },
- { "remove", l_remove },
- { "getName", l_getName },
- { "isRunning", l_isRunning },
- { 0, 0 }
- };
-
- static int luaopen_Thread(lua_State* L)
- {
- luax_newtype(L, JIN_THREAD_THREAD, thread_function);
-
- return 0;
- }
-
- static int l_newThread(lua_State* L)
- {
- const char* name = luax_checkstring(L, 1);
- const char* code = luax_checkstring(L, 2);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_THREAD_THREAD, sizeof(Proxy));
- Thread* thread = new Thread(name, code, threadRunner);
- proxy->bind(new Ref<Thread>(thread, JIN_THREAD_THREAD));
- return 1;
- }
-
- static int l_getThread(lua_State* L)
- {
- luax_getglobal(L, MODULE_NAME);
- luax_getfield(L, -1, "_curThread");
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "newThread", l_newThread },
- { "getThread", l_getThread },
- { 0, 0 }
- };
-
- int luaopen_thread(lua_State* L)
- {
- luaopen_Thread(L);
-
- luax_newlib(L, f);
-
- return 1;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/thread/Thread.h b/src/lua/modules/thread/Thread.h
deleted file mode 100644
index 60d588a..0000000
--- a/src/lua/modules/thread/Thread.h
+++ /dev/null
@@ -1,94 +0,0 @@
-#include "libjin/jin.h"
-#include "lua/common/common.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
- namespace thread
- {
-
- class Thread
- {
- public:
- typedef JinEngine::MultiThread::Thread::Variant Variant;
- typedef JinEngine::MultiThread::Thread::ThreadRunner ThreadRunner;
-
- Thread(std::string _name, std::string _code, ThreadRunner runner)
- : name(_name)
- , code(_code)
- {
- thread = new JinEngine::MultiThread::Thread(_name, runner);
- }
-
- ~Thread()
- {
- delete thread;
- }
-
- bool start(void* p)
- {
- return thread->start(p);
- }
-
- void wait()
- {
- thread->wait();
- }
-
- void send(int slot, const Variant& value)
- {
- thread->send(slot, value);
- }
-
- bool receive(int slot)
- {
- return thread->receive(slot);
- }
-
- Variant fetch(int slot)
- {
- return thread->fetch(slot);
- }
-
- Variant demand(int slot)
- {
- return thread->demand(slot);
- }
-
- void remove(int slot)
- {
- thread->remove(slot);
- }
-
- const char* getName()
- {
- return name.c_str();
- }
-
- bool isRunning()
- {
- return thread->isRunning();
- }
-
- void lock()
- {
- thread->lock();
- }
-
- void unlock()
- {
- thread->unlock();
- }
-
- const std::string name;
- const std::string code;
-
- private:
- JinEngine::MultiThread::Thread* thread;
-
- };
-
- } // thread
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/thread/je_lua_thread.cpp b/src/lua/modules/thread/je_lua_thread.cpp
new file mode 100644
index 0000000..d7b50ab
--- /dev/null
+++ b/src/lua/modules/thread/je_lua_thread.cpp
@@ -0,0 +1,248 @@
+#include "lua/modules/luax.h"
+
+#include "libjin/jin.h"
+#include "lua/jin.h"
+#include "lua/common/je_lua_common.h"
+#include "je_lua_thread.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Thread = "Thread";
+
+ typedef Shared<Thread>& SharedThread;
+
+ int luaopen_thread(lua_State* L);
+
+ static inline SharedThread checkThread(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Thread);
+ return proxy->getShared<Thread>();
+ }
+
+ LUA_IMPLEMENT int threadRunner(void* t)
+ {
+ SharedThread shared = *(Shared<Thread>*)t;
+ lua_State* L = lua_open();
+ luax_openlibs(L);
+ luaopen_jin(L);
+ luax_getglobal(L, MODULE_NAME);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread);
+ proxy->bind(&shared);
+ luax_setfield(L, -2, "_curThread");
+ luax_dostring(L, shared->code.c_str());
+ luax_close(L);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_thread_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Thread);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_start(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ bool result = shared->start(&shared);
+ luax_pushboolean(L, result);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_wait(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ shared->wait();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_send(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ const int vp = 3;
+ if (luax_isnumberstrict(L, vp))
+ {
+ float real = luax_checknumber(L, vp);
+ shared->send(slot, real);
+ }
+ else if (luax_isbooleanstrict(L, vp))
+ {
+ bool bol = luax_checkbool(L, vp);
+ shared->send(slot, bol);
+ }
+ else if (luax_isstringstrict(L, vp))
+ {
+ const char* str = luax_checkstring(L, vp);
+ shared->send(slot, str);
+ }
+ else if (luax_isuserdata(L, vp))
+ {
+ void* p = luax_touserdata(L, vp);
+ shared->send(slot, p);
+ }
+ else if (luax_islightuserdata(L, vp))
+ {
+ void* p = luax_tolightuserdata(L, vp);
+ shared->send(slot, p);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_receive(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ bool result = shared->receive(slot);
+ luax_pushboolean(L, result);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_fetch(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ Thread::Variant v = shared->fetch(slot);
+ switch (v.type)
+ {
+ case Thread::Variant::INTERGER:
+ luax_pushinteger(L, v.integer);
+ break;
+
+ case Thread::Variant::BOOLEAN:
+ luax_pushboolean(L, v.boolean);
+ break;
+
+ case Thread::Variant::CSTRING:
+ luax_pushstring(L, v.cstring);
+ break;
+
+ case Thread::Variant::REAL:
+ luax_pushnumber(L, v.real);
+ break;
+
+ case Thread::Variant::POINTER:
+ Proxy* p = (Proxy*)v.pointer;
+ Proxy* proxy = luax_newinstance(L, p->getObjectType());
+ proxy->bind(p->shared);
+ break;
+
+ }
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_demand(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ Thread::Variant v = shared->demand(slot);
+ switch (v.type)
+ {
+ case Thread::Variant::INTERGER:
+ luax_pushinteger(L, v.integer);
+ break;
+
+ case Thread::Variant::BOOLEAN:
+ luax_pushboolean(L, v.boolean);
+ break;
+
+ case Thread::Variant::CSTRING:
+ luax_pushstring(L, v.cstring);
+ break;
+
+ case Thread::Variant::REAL:
+ luax_pushnumber(L, v.real);
+ break;
+
+ case Thread::Variant::POINTER:
+ Proxy* p = (Proxy*)v.pointer;
+ const char* objType = p->getObjectType();
+ Proxy* proxy = luax_newinstance(L, objType);
+ proxy->bind(p->shared);
+ break;
+
+ }
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_remove(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ shared->remove(slot);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getName(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ const char* name = shared->getName();
+ luax_pushstring(L, name);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_isRunning(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ bool running = shared->isRunning();
+ luax_pushboolean(L, running);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int luaopen_Thread(lua_State* L)
+ {
+ luaL_Reg thread_function[] = {
+ { "__gc", l_thread_gc },
+ { "start", l_start },
+ { "wait", l_wait },
+ { "send", l_send },
+ { "receive", l_receive },
+ { "fetch", l_fetch },
+ { "demand", l_demand },
+ { "remove", l_remove },
+ { "getName", l_getName },
+ { "isRunning", l_isRunning },
+ { 0, 0 }
+ };
+
+ luax_newtype(L, Jin_Lua_Thread, thread_function);
+
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newThread(lua_State* L)
+ {
+ const char* name = luax_checkstring(L, 1);
+ const char* code = luax_checkstring(L, 2);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread);
+ Thread* thread = new Thread(name, code, threadRunner);
+ proxy->bind(new Shared<Thread>(thread, Jin_Lua_Thread));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getThread(lua_State* L)
+ {
+ luax_getglobal(L, MODULE_NAME);
+ luax_getfield(L, -1, "_curThread");
+ return 1;
+ }
+
+ LUA_EXPORT int luaopen_thread(lua_State* L)
+ {
+ luaopen_Thread(L);
+
+ luaL_Reg f[] = {
+ { "newThread", l_newThread },
+ { "getThread", l_getThread },
+ { 0, 0 }
+ };
+ luax_newlib(L, f);
+
+ return 1;
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/thread/je_lua_thread.h b/src/lua/modules/thread/je_lua_thread.h
new file mode 100644
index 0000000..a3e4e76
--- /dev/null
+++ b/src/lua/modules/thread/je_lua_thread.h
@@ -0,0 +1,93 @@
+#include "libjin/jin.h"
+#include "lua/common/je_lua_common.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Thread;
+
+ class Thread
+ {
+ public:
+ typedef JinEngine::Threads::Thread::Variant Variant;
+ typedef JinEngine::Threads::Thread::ThreadRunner ThreadRunner;
+
+ Thread(std::string _name, std::string _code, ThreadRunner runner)
+ : name(_name)
+ , code(_code)
+ {
+ thread = new JinEngine::Threads::Thread(_name, runner);
+ }
+
+ ~Thread()
+ {
+ delete thread;
+ }
+
+ bool start(void* p)
+ {
+ return thread->start(p);
+ }
+
+ void wait()
+ {
+ thread->wait();
+ }
+
+ void send(int slot, const Variant& value)
+ {
+ thread->send(slot, value);
+ }
+
+ bool receive(int slot)
+ {
+ return thread->receive(slot);
+ }
+
+ Variant fetch(int slot)
+ {
+ return thread->fetch(slot);
+ }
+
+ Variant demand(int slot)
+ {
+ return thread->demand(slot);
+ }
+
+ void remove(int slot)
+ {
+ thread->remove(slot);
+ }
+
+ const char* getName()
+ {
+ return name.c_str();
+ }
+
+ bool isRunning()
+ {
+ return thread->isRunning();
+ }
+
+ void lock()
+ {
+ thread->lock();
+ }
+
+ void unlock()
+ {
+ thread->unlock();
+ }
+
+ const std::string name;
+ const std::string code;
+
+ private:
+ JinEngine::Threads::Thread* thread;
+
+ };
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/time/je_lua_time.cpp b/src/lua/modules/time/je_lua_time.cpp
new file mode 100644
index 0000000..39ec899
--- /dev/null
+++ b/src/lua/modules/time/je_lua_time.cpp
@@ -0,0 +1,71 @@
+#include "SDL2/SDL.h"
+#include "lua/common/je_lua_common.h"
+#include "lua/modules/luax.h"
+#include "libjin/jin.h"
+
+
+#include "je_lua_timer.h"
+
+using namespace JinEngine::Time;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ static struct
+ {
+ float previous;
+ float current;
+ } context;
+
+ LUA_IMPLEMENT int l_sec(lua_State* L)
+ {
+ luax_pushnumber(L, getSecond());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_sleep(lua_State* L)
+ {
+ double sec = luax_checknumber(L, 1);
+ sleep(sec * 1000.0f);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newTimer(lua_State* L)
+ {
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Timer);
+ proxy->bind(new Shared<Timer>(new Timer(), Jin_Lua_Timer));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getDelta(lua_State* L)
+ {
+ luax_pushnumber(L, context.current - context.previous);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_step(lua_State* L)
+ {
+ context.previous = context.current;
+ context.current = getSecond();
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_time(lua_State* L)
+ {
+ luaopen_Timer(L);
+ luaL_Reg f[] = {
+ { "second", l_sec },
+ { "sleep", l_sleep },
+ { "newTimer", l_newTimer },
+ { "step", l_step },
+ { "getDelta", l_getDelta },
+ { 0, 0 },
+ };
+ luax_newlib(L, f);
+ return 1;
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/time/je_lua_time.h b/src/lua/modules/time/je_lua_time.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/time/je_lua_time.h
diff --git a/src/lua/modules/time/je_lua_timer.cpp b/src/lua/modules/time/je_lua_timer.cpp
new file mode 100644
index 0000000..540f205
--- /dev/null
+++ b/src/lua/modules/time/je_lua_timer.cpp
@@ -0,0 +1,146 @@
+
+#include "lua/common/je_lua_callback.h"
+#include "lua/common/je_lua_common.h"
+#include "je_lua_timer.h"
+
+using namespace JinEngine::Time;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Timer = "Timer";
+
+ const char* Jin_Lua_Handler = "Handler";
+
+ typedef Shared<Timer>& SharedTimer;
+
+ static Timer::TimerCallback timerCallback = [](void* data)->void
+ {
+ LuaCallback* func = static_cast<LuaCallback*>(data);
+ func->call();
+ };
+
+ static Timer::FinishCallback finishCallback = [](void* data)->void
+ {
+ LuaCallback* func = static_cast<LuaCallback*>(data);
+ delete func;
+ };
+
+ LUA_IMPLEMENT inline SharedTimer checkTimer(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Timer);
+ return proxy->getShared<Timer>();
+ }
+
+ // timer:every(time, callback, parameter)
+ LUA_IMPLEMENT int l_every(lua_State* L)
+ {
+ int n = luax_gettop(L);
+ SharedTimer shared = checkTimer(L);
+ Timer* timer = shared.getObject();
+ float s = luax_checknumber(L, 2);
+ LuaCallback* func = new LuaCallback(L);
+ func->setFunc(3);
+ for(int i = 4; i <= n; ++i)
+ func->pushParam(i);
+ Timer::Handler* handler = timer->every(s, timerCallback, func, finishCallback);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler);
+ Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler);
+ shrHandler->retain();
+ proxy->bind(shrHandler);
+ return 1;
+ }
+
+ // timer:after(time, callback, parameter)
+ LUA_IMPLEMENT int l_after(lua_State* L)
+ {
+ int n = luax_gettop(L);
+ SharedTimer shared = checkTimer(L);
+ Timer* timer = shared.getObject();
+ float s = luax_checknumber(L, 2);
+ LuaCallback* func = new LuaCallback(L);
+ func->setFunc(3);
+ for (int i = 4; i <= n; ++i)
+ func->pushParam(i);
+ Timer::Handler* handler = timer->after(s, timerCallback, func, finishCallback);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler);
+ Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler);
+ shrHandler->retain();
+ proxy->bind(shrHandler);
+ return 1;
+ }
+
+ // timer:repeat(time, callback, parameter)
+ LUA_IMPLEMENT int l_repeat(lua_State* L)
+ {
+ int n = luax_gettop(L);
+ SharedTimer shared = checkTimer(L);
+ Timer* timer = shared.getObject();
+ float s = luax_checknumber(L, 2);
+ int count = luax_checkinteger(L, 3);
+ LuaCallback* func = new LuaCallback(L);
+ func->setFunc(4);
+ for (int i = 5; i <= n; ++i)
+ func->pushParam(i);
+ Timer::Handler* handler = timer->repeat(s, count, timerCallback, func, finishCallback);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler);
+ Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler);
+ shrHandler->retain();
+ proxy->bind(shrHandler);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_update(lua_State* L)
+ {
+ SharedTimer shared = checkTimer(L);
+ Timer* timer = shared.getObject();
+ float s = luax_checknumber(L, 2);
+ timer->update(s);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_cancel(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Timer);
+ Timer* timer = p->getObject<Timer>();
+ Proxy* ph = (Proxy*)luax_checktype(L, 2, Jin_Lua_Handler);
+ Timer::Handler* handler = ph->getObject<Timer::Handler>();
+ timer->cancel(handler);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_cancelAll(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Timer);
+ Timer* timer = p->getObject<Timer>();
+ timer->cancelAll();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Timer);
+ p->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Timer(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "every", l_every },
+ { "after", l_after },
+ { "duplicate", l_repeat },
+ { "update", l_update },
+ { "cancel", l_cancel },
+ { "cancelAll", l_cancelAll },
+ { 0, 0 }
+ };
+
+ luax_newtype(L, Jin_Lua_Timer, f);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/time/je_lua_timer.h b/src/lua/modules/time/je_lua_timer.h
new file mode 100644
index 0000000..35ec15d
--- /dev/null
+++ b/src/lua/modules/time/je_lua_timer.h
@@ -0,0 +1,20 @@
+#ifndef __JE_LUA_TIMER_H__
+#define __JE_LUA_TIMER_H__
+
+#include "libjin/jin.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Timer;
+
+ extern const char* Jin_Lua_Handler;
+
+ void luaopen_Timer(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/time/time.cpp b/src/lua/modules/time/time.cpp
deleted file mode 100644
index f6e6f26..0000000
--- a/src/lua/modules/time/time.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "lua/modules/luax.h"
-#include <SDL2/SDL.h>
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Time;
-
- static int l_sec(lua_State* L)
- {
- luax_pushnumber(L, getSecond());
- return 1;
- }
-
- static int l_sleep(lua_State* L)
- {
- double sec = luax_checknumber(L, 1);
- sleep(sec * 1000.0f);
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "second", l_sec },
- { "sleep", l_sleep },
- { 0, 0 },
- };
-
- int luaopen_time(lua_State* L)
- {
- luax_newlib(L, f);
- return 1;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/types.h b/src/lua/modules/types.h
deleted file mode 100644
index 123604e..0000000
--- a/src/lua/modules/types.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef __JIN_MODULES_TYPES_H
-#define __JIN_MODULES_TYPES_H
-
-// graphics module
-#define JIN_GRAPHICS_TEXTURE "Texture"
-#define JIN_GRAPHICS_SHADER "Shader"
-#define JIN_GRAPHICS_CANVAS "Canvas"
-#define JIN_GRAPHICS_TEXT "Text"
-#define JIN_GRAPHICS_TTFDATA "TTFData"
-#define JIN_GRAPHICS_TTF "TTF"
-#define JIN_GRAPHICS_TEXTUREFONT "TextureFont"
-#define JIN_GRAPHICS_PAGE "Page"
-#define JIN_GRAPHICS_BITMAP "Bitmap"
-
-// audio module
-#define JIN_AUDIO_SOURCE "Source"
-
-// thread module
-#define JIN_THREAD_THREAD "Thread"
-
-// network module
-#define JIN_NETWORK_SOCKET "Socket"
-#define JIN_NETWORK_BUFFER "Buffer"
-
-#endif \ No newline at end of file
diff --git a/src/lua/resources/font.ttf b/src/lua/resources/font.ttf
deleted file mode 100644
index 153c608..0000000
--- a/src/lua/resources/font.ttf
+++ /dev/null
Binary files differ
diff --git a/src/lua/resources/font.ttf.h b/src/lua/resources/font.ttf.h
index bb0734f..b220738 100644
--- a/src/lua/resources/font.ttf.h
+++ b/src/lua/resources/font.ttf.h
@@ -2,361 +2,365 @@ static const char
default_font_bitmap[] =
{ 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,3,154,0,0,0,14,8,6,0,0,0,78,
234,99,67,0,0,0,4,103,65,77,65,0,0,177,143,11,252,97,5,0,0,0,9,112,72,89,115,
-0,0,14,194,0,0,14,194,1,21,40,74,128,0,0,0,25,116,69,88,116,83,111,102,116,
-119,97,114,101,0,112,97,105,110,116,46,110,101,116,32,52,46,48,46,50,49,241,
-32,105,149,0,0,29,22,73,68,65,84,120,94,237,92,61,168,109,75,82,126,8,134,166,
-26,138,32,152,152,60,16,68,12,6,28,159,130,136,129,58,193,168,136,99,96,224,4,
-38,47,83,208,64,197,224,129,168,32,19,61,13,12,100,20,20,196,72,196,216,159,
-200,68,19,49,209,72,65,20,19,17,217,246,87,95,215,174,175,126,122,239,117,206,
-61,87,158,48,181,169,123,86,87,125,93,93,127,221,107,173,125,238,189,31,220,
-62,184,221,192,31,20,114,249,164,115,82,204,35,28,232,10,238,10,6,116,21,7,
-122,132,123,169,141,43,248,9,247,104,222,132,159,104,194,169,76,229,87,232,
-234,188,171,56,208,251,192,42,238,132,125,164,3,93,153,251,104,62,232,165,184,
-61,124,74,111,105,247,173,48,78,142,189,106,243,25,206,233,125,224,21,115,5,
-183,135,15,73,237,93,153,243,8,127,146,59,61,211,43,93,193,94,193,76,164,243,
-174,206,125,41,30,116,117,206,85,92,165,151,204,187,130,123,169,173,183,198,
-130,94,138,175,116,117,238,75,214,120,107,155,142,59,97,85,127,194,40,93,197,
-190,47,123,255,223,112,239,34,175,58,167,147,254,165,114,167,103,122,208,85,
-125,197,60,155,7,58,97,92,94,117,39,185,147,234,79,24,167,215,98,183,40,209,
-85,253,30,38,250,44,233,78,228,115,222,199,188,43,24,165,151,226,157,238,243,
-238,179,11,87,73,30,5,87,73,30,5,87,201,73,174,60,75,201,251,74,13,236,208,44,
-56,149,143,137,169,24,227,219,237,211,197,159,96,164,100,200,140,221,154,32,
-67,60,192,108,41,237,63,192,41,65,119,199,125,225,126,5,255,64,159,222,37,87,
-109,56,95,141,243,118,251,207,197,95,18,153,95,125,105,241,191,44,254,72,116,
-160,143,22,67,14,253,182,58,218,197,218,234,191,243,158,241,152,128,147,57,
-199,121,134,186,128,3,25,242,141,177,134,202,184,132,13,73,215,57,153,246,160,
-47,186,113,62,200,80,47,199,109,233,153,10,254,157,236,190,22,115,31,9,155,60,
-99,111,183,95,76,163,96,236,171,44,225,124,149,40,87,252,201,238,98,179,195,
-79,72,39,60,100,85,250,28,71,251,170,87,238,113,53,155,105,254,35,31,186,46,
-143,170,190,172,147,248,9,214,124,226,231,136,1,59,37,121,181,13,158,236,203,
-120,152,147,71,19,243,19,146,193,63,227,151,246,214,98,211,95,181,15,86,108,
-220,35,50,171,31,143,108,213,92,20,172,249,230,227,11,88,208,93,246,0,159,112,
-39,214,249,101,173,196,15,112,109,157,215,216,204,81,100,230,39,75,116,148,
-237,144,79,53,3,87,123,87,234,187,174,156,18,6,156,113,87,237,129,243,200,185,
-198,115,202,97,197,93,93,247,5,254,89,188,252,60,151,187,159,83,61,106,12,29,
-51,219,124,34,119,50,237,3,61,200,16,131,254,46,169,62,241,185,235,171,246,
-211,101,37,14,167,53,138,185,154,223,154,83,159,95,215,42,118,155,158,188,87,
-203,4,185,96,140,183,106,164,132,173,189,48,244,64,26,169,95,213,103,126,56,
-170,118,31,205,203,107,102,221,213,245,234,188,194,78,107,148,145,213,230,137,
-235,188,136,239,227,197,246,204,63,229,206,214,84,137,114,181,249,12,239,172,
-243,170,206,185,74,242,40,184,74,242,40,184,74,110,183,111,177,171,42,87,158,
-165,228,125,165,6,44,120,144,73,67,62,54,115,197,24,127,150,95,52,127,198,254,
-140,23,185,223,16,221,85,27,206,95,123,209,108,100,200,55,198,26,42,227,18,54,
-36,93,231,100,90,215,127,238,126,69,198,56,75,246,172,76,134,122,57,110,75,
-207,84,240,239,100,247,181,152,61,66,191,253,215,98,28,166,91,107,31,31,129,
-208,155,255,97,87,65,31,167,27,4,56,231,24,125,170,212,241,92,179,18,15,116,
-112,173,209,140,255,56,97,136,171,107,35,190,105,47,130,43,246,147,230,39,152,
-107,227,129,228,195,197,154,191,121,63,234,126,206,58,191,58,157,3,176,143,
-117,162,30,92,163,198,0,106,103,198,146,103,223,163,118,147,239,96,207,233,
-148,71,215,225,204,83,13,108,230,135,51,112,212,223,99,80,98,60,189,166,19,
-246,211,39,189,5,127,148,162,103,122,252,115,47,64,171,190,240,97,164,246,121,
-238,217,217,87,167,220,3,90,223,37,145,156,247,126,9,187,17,71,240,132,71,252,
-181,38,192,193,119,91,111,115,239,49,214,33,114,16,56,158,1,129,59,249,132,49,
-228,31,10,214,251,164,18,253,113,92,212,16,54,156,24,71,237,11,222,179,29,155,
-237,56,19,83,107,50,219,99,125,61,78,16,99,128,141,192,89,157,64,91,18,121,
-201,56,183,87,251,240,211,182,238,28,115,206,31,184,219,114,202,251,146,235,
-106,190,89,75,237,211,25,199,28,214,56,118,204,38,189,34,143,124,79,231,133,
-238,159,169,102,179,205,39,114,39,211,62,208,131,12,81,244,50,3,53,168,123,
-169,159,101,148,165,115,21,180,116,97,155,189,135,154,125,210,114,202,121,167,
-179,253,247,22,255,214,226,222,3,228,189,90,38,200,5,99,188,85,35,37,44,123,1,
-107,195,223,143,90,175,68,143,118,191,217,67,244,21,18,245,131,57,240,30,203,
-245,14,57,251,83,115,20,235,193,159,156,7,250,192,61,7,137,174,151,253,244,
-125,76,251,148,123,236,49,7,76,223,177,14,40,98,9,121,95,11,204,188,229,179,
-170,230,46,143,126,121,49,124,1,127,197,100,213,102,196,0,174,123,62,98,1,206,
-81,129,207,92,37,121,20,92,37,252,243,27,23,255,210,226,239,218,227,9,247,23,
-139,191,167,201,149,103,41,121,95,169,97,43,16,200,164,33,31,155,185,98,140,
-125,211,149,41,134,204,216,173,9,50,196,3,204,150,210,254,3,156,18,116,119,28,
-27,6,5,196,38,255,176,52,203,158,209,201,80,129,35,95,141,19,27,43,31,64,170,
-173,58,208,243,195,141,184,126,88,146,247,140,199,4,156,204,57,206,51,212,5,
-28,200,144,111,140,53,84,198,37,108,72,186,206,201,180,174,231,161,136,220,
-242,32,173,249,31,230,131,12,245,114,220,150,158,169,224,223,201,238,107,48,
-247,43,246,211,191,46,158,111,38,224,210,155,251,39,110,44,249,197,135,57,246,
-195,187,30,232,216,55,245,198,155,111,98,100,224,40,235,123,164,227,123,29,65,
-220,35,42,85,220,116,163,11,44,230,158,94,186,238,88,203,105,224,251,126,212,
-156,101,157,95,69,47,170,158,246,177,14,111,126,252,201,155,120,189,201,149,
-186,152,79,252,76,24,216,112,155,206,88,11,103,34,117,170,1,199,218,113,227,
-39,195,38,124,204,190,179,254,240,5,120,228,197,53,192,195,78,127,137,239,241,
-250,56,159,245,180,237,118,180,182,142,167,76,111,208,96,175,79,72,48,6,62,
-247,87,216,86,63,240,64,24,15,65,244,193,57,234,135,177,218,2,23,189,213,134,
-154,222,47,248,226,83,253,10,77,228,198,37,96,250,88,177,136,17,164,117,226,
-90,250,197,42,215,2,86,115,130,235,79,6,28,108,33,39,140,81,253,81,108,206,11,
-56,112,90,111,226,212,166,227,166,190,0,14,132,254,236,251,4,76,123,136,209,
-99,14,123,189,30,88,15,113,2,115,90,87,235,4,142,156,62,239,91,114,237,63,204,
-163,143,154,239,222,47,61,135,176,11,251,245,133,20,125,133,252,217,158,95,28,
-125,243,28,151,123,129,204,152,249,121,46,215,184,85,78,221,111,46,246,94,65,
-188,245,92,156,109,62,145,59,153,246,129,30,100,136,162,223,35,248,197,179,50,
-244,32,200,17,79,244,23,123,31,249,2,155,212,236,168,109,214,149,251,166,247,
-6,114,206,103,205,44,71,238,32,199,11,73,215,147,187,132,210,166,49,167,14,
-148,176,209,35,248,137,117,115,93,216,123,238,91,254,210,162,230,66,251,155,
-57,64,159,178,183,181,167,57,47,114,174,54,185,94,228,93,123,146,243,194,166,
-174,23,126,178,255,40,245,216,32,39,114,190,7,208,255,243,53,230,212,121,190,
-7,127,97,49,112,95,94,156,251,7,107,241,10,235,195,103,196,133,121,244,79,115,
-2,102,206,208,31,245,30,9,198,92,236,217,220,83,25,19,92,37,121,20,92,37,252,
-243,231,23,255,227,98,212,156,26,197,128,111,183,111,93,252,223,77,174,204,63,
-127,120,241,15,236,107,240,183,217,207,61,82,195,187,61,135,205,28,87,193,181,
-144,96,223,116,89,218,177,81,152,224,90,140,9,227,246,179,52,143,148,117,93,
-54,111,108,126,109,236,71,54,170,95,224,171,113,98,110,158,175,218,110,91,55,
-229,99,28,214,238,15,182,192,101,201,204,147,159,170,119,174,235,214,145,242,
-85,155,224,138,197,88,245,206,125,253,110,87,49,147,29,93,43,122,128,15,45,
-185,7,174,231,225,10,238,132,81,126,75,187,47,197,196,149,223,92,112,40,70,
-239,241,227,88,80,237,205,24,43,142,57,70,127,230,131,223,57,251,0,242,131,
-188,98,185,199,106,141,10,126,60,175,136,227,30,217,24,144,161,92,207,195,254,
-186,159,224,105,109,106,230,253,120,202,81,88,142,94,84,61,237,99,29,172,7,76,
-60,44,214,189,83,234,98,62,241,51,97,226,91,244,208,98,30,234,207,30,208,121,
-224,136,25,55,90,127,57,128,6,63,33,207,190,179,254,243,249,168,177,168,52,
-199,235,82,92,159,94,198,172,174,133,225,15,108,247,223,60,245,57,240,131,121,
-87,108,228,34,247,67,217,55,150,99,142,194,142,105,236,227,56,80,210,203,188,
-222,47,241,240,17,181,38,135,13,151,128,59,214,235,1,214,220,179,22,243,67,30,
-243,69,198,117,206,7,113,181,54,248,137,241,248,155,192,251,72,115,222,207,
-224,218,31,97,211,37,96,174,15,158,115,0,158,239,29,92,91,99,6,135,61,231,9,
-167,122,248,133,126,96,252,213,30,115,3,189,214,235,180,71,97,131,125,114,194,
-173,145,228,48,108,247,117,177,158,246,233,156,31,173,1,57,252,80,156,175,203,
-207,115,185,250,166,114,112,206,49,215,87,137,235,115,239,156,229,107,164,100,
-218,7,122,144,33,138,126,143,230,62,155,242,130,156,151,60,155,29,181,77,12,
-242,59,245,6,108,66,247,232,69,243,43,109,30,217,175,114,223,240,163,184,30,
-188,80,194,254,142,253,137,120,248,133,33,198,170,103,44,200,79,223,179,212,
-133,47,90,163,58,143,159,58,15,189,153,251,152,186,200,239,35,157,174,199,62,
-65,14,225,11,214,197,56,214,247,158,171,125,196,223,46,194,166,227,129,123,92,
-95,206,243,61,228,115,122,143,242,12,2,102,162,83,191,249,217,235,177,128,32,
-131,63,158,235,184,31,199,108,231,239,94,252,199,77,122,187,253,219,226,31,
-219,163,224,60,2,225,207,127,88,252,125,54,186,221,190,121,241,9,215,229,202,
-183,219,175,217,159,164,95,89,12,233,191,47,254,38,199,168,1,75,52,200,164,33,
-7,225,79,77,228,244,235,99,16,48,254,48,227,212,55,97,52,18,154,222,41,63,228,
-16,131,66,84,202,47,154,113,163,81,255,88,92,109,136,110,43,214,155,109,160,
-49,185,65,92,235,220,227,68,28,249,175,6,16,247,78,127,117,118,49,214,161,237,
-140,235,7,56,229,110,23,135,152,147,111,16,167,233,219,55,95,23,243,188,38,
-204,161,226,230,60,209,191,107,54,249,48,51,247,195,243,90,131,185,54,106,3,
-91,240,49,242,64,59,234,91,254,107,76,125,141,156,67,173,11,37,113,160,101,28,
-242,201,252,100,92,248,219,109,97,109,198,31,227,186,62,236,42,6,177,228,58,
-244,181,29,167,107,99,62,236,40,209,174,99,34,43,240,195,237,193,14,248,233,
-11,205,226,152,151,113,145,179,45,85,90,146,106,87,215,39,134,154,147,253,132,
-55,174,251,142,56,238,17,149,230,243,160,249,153,120,182,217,215,38,115,45,
-149,128,53,103,89,231,87,209,35,170,15,223,176,119,80,183,240,145,31,197,166,
-186,88,254,206,24,216,209,26,130,145,35,200,249,83,231,129,115,204,209,31,180,
-9,249,195,51,204,9,215,139,35,231,121,206,84,139,158,211,130,115,194,245,102,
-248,54,157,111,181,23,34,142,124,62,192,247,156,111,112,206,167,174,25,245,
-235,56,80,210,203,188,30,27,250,45,226,131,222,53,196,246,47,92,106,206,176,
-22,30,82,240,133,0,228,208,71,45,52,39,113,142,99,46,244,96,218,209,124,100,
-28,108,194,94,172,153,207,136,184,162,62,206,49,126,168,161,95,240,83,123,48,
-242,228,18,242,51,189,97,156,182,36,114,88,251,32,226,1,71,254,116,175,7,198,
-115,135,223,96,16,215,251,10,24,61,103,129,59,253,45,12,196,12,189,83,183,151,
-71,152,211,123,20,28,47,235,172,3,123,100,250,82,174,246,125,244,131,226,214,
-44,203,31,63,207,229,90,67,149,131,35,127,145,95,213,107,125,178,28,53,70,46,
-71,223,156,48,22,93,211,131,12,33,122,65,51,103,61,79,222,215,209,95,121,63,
-90,158,155,109,212,207,109,214,90,114,126,191,143,184,220,185,214,150,236,87,
-225,23,165,29,203,26,79,52,229,151,123,200,125,86,61,99,97,31,65,162,107,69,
-46,88,115,141,149,243,162,87,117,30,117,209,115,125,30,124,130,205,199,47,154,
-170,139,252,97,77,167,56,107,232,127,127,63,209,216,226,154,121,8,84,175,7,
-253,192,243,43,176,156,95,49,209,243,192,226,217,20,185,2,158,62,213,30,208,
-124,169,221,240,9,215,196,196,28,191,250,206,197,127,184,248,239,23,255,248,
-93,234,124,187,125,126,241,31,217,149,190,112,118,220,143,44,254,171,61,250,
-179,197,191,106,215,29,199,171,42,87,190,221,254,103,241,183,239,209,31,64,
-176,232,119,23,223,231,169,1,219,72,32,147,134,28,132,160,189,32,209,56,138,
-33,14,73,226,139,7,37,248,217,15,15,202,129,139,34,247,98,196,92,74,176,46,
-198,121,3,177,41,189,113,92,202,130,233,129,194,195,25,182,216,188,170,11,27,
-216,212,104,18,31,51,22,199,57,247,56,49,158,30,6,222,229,69,51,252,153,55,
-205,244,96,139,121,190,41,32,65,126,65,192,99,12,253,84,15,207,173,199,239,
-227,233,48,98,172,33,197,26,192,78,177,168,77,72,35,166,140,13,191,40,241,56,
-114,173,137,197,218,92,207,165,161,131,47,186,94,62,20,162,7,152,251,94,175,
-208,81,2,59,176,87,111,150,208,123,157,32,137,121,129,193,92,30,204,148,248,
-203,177,247,60,226,200,118,233,31,228,200,19,230,245,131,246,202,218,249,102,
-22,120,181,19,135,163,175,135,235,168,101,223,143,176,3,157,82,255,102,84,115,
-182,36,149,12,157,241,169,102,134,161,166,199,21,120,165,211,30,69,76,74,140,
-43,244,201,207,205,200,133,211,212,123,117,109,165,105,63,70,238,179,206,175,
-78,49,186,111,32,248,100,26,203,77,207,95,234,135,11,24,228,197,109,198,250,
-148,229,126,228,92,173,15,240,200,55,100,152,3,121,245,189,249,3,194,245,102,
-246,155,74,122,45,96,131,123,229,1,78,9,227,197,140,109,62,47,149,124,157,156,
-43,158,111,208,129,216,47,208,228,7,11,93,79,243,151,109,129,139,94,230,209,
-79,197,198,126,196,250,158,111,48,207,144,26,19,207,10,173,37,174,193,88,139,
-117,225,250,60,67,242,126,246,43,207,231,189,199,246,167,226,96,11,113,224,
-139,15,218,123,140,101,237,66,19,218,176,101,253,177,57,242,228,18,242,51,189,
-98,156,17,11,243,87,207,48,230,216,235,11,162,143,138,227,217,169,125,22,215,
-181,6,196,42,99,237,233,57,0,117,209,231,5,216,205,231,17,217,175,162,238,148,
-102,123,113,159,80,154,94,160,176,78,93,119,58,47,217,155,117,157,147,92,253,
-83,57,56,231,111,250,210,39,116,89,14,31,145,147,108,179,230,88,107,69,54,31,
-149,12,33,250,125,21,61,84,109,176,39,225,83,212,35,239,199,121,127,240,188,
-128,110,252,210,96,240,229,46,119,50,109,214,107,204,225,23,198,61,246,30,188,
-80,194,62,203,99,244,20,226,165,87,174,203,207,10,57,86,230,32,114,164,243,
-168,139,253,174,243,184,30,230,33,190,233,183,150,81,47,237,107,234,188,135,
-160,7,107,143,195,143,211,47,83,208,95,32,204,197,23,114,196,6,245,58,50,6,
-216,198,26,92,167,98,34,183,136,7,140,181,96,27,126,78,47,175,88,211,113,81,
-95,202,152,71,174,249,21,153,243,19,139,127,127,49,98,248,185,197,212,184,62,
-112,126,245,29,139,255,124,241,223,44,254,98,194,128,111,183,63,93,252,179,
-123,244,189,139,241,79,167,190,110,192,241,170,202,149,187,228,235,239,215,91,
-162,6,118,123,142,7,11,254,244,100,59,77,15,37,94,56,149,66,86,31,24,128,241,
-132,158,214,76,152,205,180,175,146,104,186,74,108,96,199,69,195,240,70,169,
-205,18,54,80,104,151,198,6,113,137,115,143,19,243,242,122,196,189,246,69,19,
-62,210,30,52,115,163,158,94,52,105,151,146,136,161,142,243,188,138,3,79,185,
-158,112,145,187,231,88,200,128,173,113,95,171,53,184,231,94,235,8,251,216,136,
-188,137,67,170,7,88,244,0,252,154,254,189,91,232,40,153,99,139,67,217,125,166,
-79,122,32,18,3,63,193,176,7,140,31,110,115,30,232,159,199,16,135,167,214,63,
-236,250,218,188,214,181,227,42,247,181,218,225,225,232,107,121,223,199,56,219,
-3,65,167,245,116,219,15,95,26,42,45,76,181,27,123,103,227,241,51,201,31,224,
-141,181,198,129,211,28,145,21,87,252,44,204,122,86,233,180,54,153,107,169,4,
-172,57,203,58,191,138,126,83,125,248,230,191,157,138,56,248,81,108,170,139,
-229,239,49,6,140,26,227,39,227,36,10,215,211,153,94,99,6,30,243,127,106,49,
-228,167,51,236,238,15,8,215,139,35,231,121,142,203,149,250,77,95,231,47,137,
-19,174,55,51,158,62,79,123,193,253,135,159,57,87,241,64,229,56,80,251,171,149,
-178,38,98,100,253,76,99,31,199,129,146,94,230,209,31,197,198,76,205,95,228,
-190,246,56,207,10,96,112,175,192,156,120,49,241,90,146,25,183,238,253,136,19,
-126,248,189,198,114,154,112,121,69,207,7,113,212,78,54,177,158,231,154,49,43,
-142,53,84,95,193,145,39,151,144,159,233,117,93,228,0,117,189,175,93,98,169,
-245,5,211,87,173,111,63,95,163,231,234,153,184,70,78,91,50,251,153,237,129,
-231,125,16,254,69,221,49,230,39,112,212,71,15,115,93,238,105,197,177,71,188,
-110,32,228,157,185,87,220,142,3,63,69,118,150,107,13,85,14,142,53,25,111,173,
-1,239,59,253,204,62,201,163,174,78,245,140,50,31,149,32,187,235,35,167,103,
-159,184,6,242,173,117,243,171,208,81,26,26,198,10,155,111,251,162,153,107,166,
-212,238,73,219,204,72,5,187,165,36,140,69,7,202,251,50,235,253,10,126,229,243,
-149,57,136,115,70,231,81,135,188,241,60,211,121,92,135,123,5,18,173,187,247,
-130,238,3,151,112,127,98,45,248,226,82,239,127,124,17,70,155,167,254,34,123,
-77,113,15,131,45,196,14,27,136,63,63,111,228,61,9,61,158,203,234,253,11,115,
-245,221,72,233,227,161,223,216,51,186,38,53,204,47,175,153,211,152,243,235,
-246,39,34,9,75,217,46,56,143,190,127,241,63,45,254,235,36,5,223,110,63,36,35,
-240,15,46,254,134,36,1,251,85,149,43,207,82,242,190,82,3,187,5,199,38,68,81,
-88,112,50,174,167,135,146,218,0,51,150,24,54,166,115,63,96,58,198,237,171,68,
-215,200,216,233,191,76,142,194,230,166,159,108,196,6,113,137,115,143,19,243,
-152,159,140,123,205,139,38,54,12,190,93,136,27,73,111,84,230,70,101,148,135,
-93,74,34,134,58,206,243,42,14,60,229,122,194,157,106,60,97,195,191,140,189,86,
-107,112,207,125,228,134,135,16,24,235,96,227,231,154,68,15,208,7,237,1,176,
-234,40,153,99,203,118,226,129,91,123,56,247,27,94,24,224,51,236,210,30,190,
-173,170,15,46,156,3,12,106,63,191,104,242,192,244,181,127,116,49,236,95,249,
-109,37,244,129,137,7,170,137,114,222,192,244,11,107,210,39,50,235,166,184,176,
-91,235,73,238,251,60,246,142,226,220,247,154,163,130,31,207,43,226,238,62,56,
-25,202,245,131,159,134,225,53,215,246,145,243,180,54,53,61,15,96,205,89,214,
-249,149,247,71,205,117,244,93,244,3,214,56,61,36,221,235,98,62,105,156,3,102,
-49,226,139,127,26,16,178,233,76,175,245,113,223,156,243,94,102,94,153,191,144,
-58,99,45,196,82,207,31,141,55,52,53,214,199,189,229,121,122,246,111,52,125,
-173,158,79,238,45,229,169,126,204,49,71,136,7,122,224,96,167,174,91,243,238,
-76,127,84,146,103,122,254,34,143,53,23,244,213,237,35,111,192,122,141,48,199,
-231,51,167,234,91,156,77,172,5,49,184,174,15,104,199,88,77,222,109,134,157,
-141,1,37,220,92,107,92,67,150,247,65,204,138,181,179,94,207,67,143,197,52,109,
-221,192,42,119,187,244,29,182,38,202,53,187,98,15,204,248,188,255,192,145,3,
-197,209,94,207,79,141,67,251,130,60,219,139,251,128,51,252,235,231,205,178,
-254,48,95,248,169,114,174,199,251,142,202,193,156,227,189,215,109,174,209,139,
-214,114,185,115,213,175,81,37,67,184,158,243,243,62,84,61,152,122,228,79,235,
-166,136,200,119,63,47,184,199,14,126,153,116,144,59,153,54,235,53,230,240,11,
-227,190,6,8,126,77,84,239,95,123,69,18,198,162,211,115,155,125,167,250,232,35,
-234,245,89,35,246,125,175,55,117,145,123,157,199,245,98,223,107,108,140,63,
-246,18,176,174,211,222,163,196,25,182,64,189,78,100,29,121,156,176,129,251,32,
-100,176,11,121,222,187,81,11,224,97,155,177,42,134,177,196,252,192,18,81,125,
-161,14,28,185,225,53,206,29,216,232,251,153,127,242,223,101,222,110,255,188,
-248,139,38,115,125,198,225,37,242,47,23,255,237,226,159,52,217,140,235,92,37,
-39,185,242,44,37,239,43,53,176,91,112,104,66,38,0,201,195,8,63,65,211,67,9,
-146,116,191,209,44,6,150,227,140,67,98,33,247,102,193,207,47,23,12,230,198,
-195,54,127,98,156,55,16,155,25,69,99,195,82,138,185,249,155,4,226,96,131,7,
-109,111,122,248,174,54,96,147,235,59,206,153,216,104,36,174,199,185,25,247,46,
-127,117,54,114,167,190,18,135,181,167,7,219,176,75,137,218,203,227,60,175,226,
-192,140,81,113,145,39,176,75,79,53,134,77,200,21,203,185,122,112,16,123,173,
-214,196,210,47,149,134,142,255,35,24,71,248,201,92,184,62,122,128,242,238,135,
-251,12,127,32,193,79,208,163,7,2,124,41,192,24,251,77,200,243,10,140,251,5,44,
-198,253,55,47,145,95,196,135,181,217,83,122,8,231,67,31,220,49,140,19,54,180,
-159,243,141,42,252,167,239,193,240,147,123,83,165,17,139,199,225,243,115,141,
-34,238,90,123,224,49,174,125,18,113,134,116,142,235,132,175,24,226,184,71,214,
-200,201,80,174,63,251,9,198,120,234,189,180,182,217,164,230,180,31,35,103,42,
-231,218,96,206,235,125,232,185,197,122,144,32,231,216,15,211,111,249,106,93,
-122,62,58,198,237,105,220,184,158,206,244,169,62,62,31,185,203,245,100,108,
-174,71,124,174,241,92,63,250,235,116,22,175,147,161,20,119,174,153,207,167,
-108,190,177,43,30,254,193,70,253,150,29,235,43,110,170,31,125,227,8,118,160,7,
-142,222,6,238,116,95,137,181,21,155,237,194,15,96,136,51,173,125,2,223,207,
-129,26,31,214,196,189,174,251,22,249,242,250,68,254,114,47,170,79,41,86,147,
-103,155,94,23,239,217,96,237,71,158,77,218,83,190,246,248,91,161,125,21,107,
-103,125,61,51,179,182,239,3,172,171,56,230,77,99,102,143,41,135,127,125,159,
-34,102,232,21,55,253,213,237,154,27,175,111,142,135,185,1,22,118,230,60,131,
-117,62,37,115,79,229,88,206,121,118,220,156,175,238,39,115,254,65,203,7,184,
-230,175,238,197,243,90,115,12,11,165,132,177,232,154,30,100,8,215,247,126,203,
-122,176,230,60,228,180,197,17,124,227,115,163,250,77,219,228,26,143,207,231,
-167,201,157,76,155,245,134,217,87,169,23,246,71,113,61,120,161,130,221,82,18,
-198,162,243,88,98,31,169,158,53,155,251,39,242,203,243,71,231,81,7,223,121,
-134,246,121,145,215,171,186,216,239,92,143,236,190,129,40,175,245,136,243,50,
-124,213,53,244,218,145,96,230,3,115,192,184,230,218,138,97,126,16,39,116,176,
-133,151,87,216,155,115,173,57,161,93,16,122,31,191,180,192,79,80,190,79,198,
-108,240,231,22,255,201,226,233,55,149,248,13,230,223,45,254,233,197,161,81,12,
-56,143,130,171,228,36,87,158,165,228,125,165,6,44,41,32,147,134,28,132,4,59,
-161,24,108,56,197,16,135,68,251,191,69,3,225,97,35,55,24,152,141,228,9,6,193,
-94,46,48,49,186,46,48,88,59,63,0,230,27,174,19,27,73,15,57,54,67,52,147,54,98,
-222,72,78,241,141,191,227,156,105,159,27,146,140,88,122,12,239,254,159,1,121,
-252,57,102,202,255,239,95,52,231,60,241,70,84,107,28,54,241,159,38,57,49,71,
-154,123,240,213,90,131,123,238,195,86,247,45,31,138,221,255,156,195,238,199,
-220,235,249,208,98,143,99,204,79,197,192,95,198,93,231,212,60,100,172,251,89,
-255,7,53,191,242,253,131,159,185,215,233,15,214,80,226,154,25,195,27,251,146,
-216,190,167,6,12,63,114,110,88,79,223,215,78,253,165,33,226,174,181,152,207,
-130,136,67,41,234,171,113,61,194,43,134,56,238,145,53,114,90,242,176,21,126,
-130,129,83,98,79,43,2,204,181,239,181,52,155,212,112,45,197,130,117,95,101,
-185,247,24,215,233,125,224,185,99,109,201,30,119,61,11,166,186,124,117,192,
-232,254,158,236,35,7,87,95,52,193,192,247,60,69,94,39,191,184,94,175,105,242,
-199,201,80,138,59,247,22,40,246,97,207,231,189,23,132,49,102,92,46,233,251,31,
-84,31,204,233,27,71,88,15,121,69,172,244,54,112,167,243,18,52,190,84,137,93,
-159,67,255,76,107,159,132,223,87,222,23,90,203,199,243,181,118,49,7,177,32,
-135,218,3,234,83,138,213,228,221,230,68,185,71,162,134,138,71,206,123,95,196,
-40,214,206,122,208,148,95,16,99,87,44,235,171,235,18,83,206,87,167,45,113,251,
-211,111,202,107,143,195,118,143,131,235,122,126,65,243,89,200,126,73,251,205,
-252,224,167,218,211,62,61,157,173,213,191,211,254,131,111,124,46,202,114,224,
-115,253,40,119,187,253,188,96,125,225,27,99,232,107,33,46,172,85,207,68,248,0,
-155,89,190,102,43,97,44,186,166,7,25,194,245,241,98,194,30,179,25,246,241,17,
-8,241,192,95,141,147,182,56,10,159,53,199,148,99,222,39,83,239,218,124,126,
-154,220,201,180,89,111,152,125,21,126,81,218,176,219,204,72,5,187,165,36,140,
-69,231,61,133,122,247,30,166,46,124,209,125,80,231,169,221,152,199,123,143,
-230,142,186,232,187,71,58,93,143,123,196,243,174,4,31,84,158,239,147,236,75,
-216,140,243,154,236,251,104,222,67,244,69,207,140,254,69,18,109,143,252,36,
-215,32,252,84,109,176,214,160,234,200,159,111,146,219,237,183,101,20,92,37,
-121,20,92,37,39,185,242,44,37,239,43,53,96,73,1,153,52,228,32,29,145,235,161,
-11,102,19,116,174,155,112,42,76,181,119,42,94,95,55,143,148,249,225,168,218,
-83,159,102,191,163,41,171,230,20,103,245,13,227,44,243,171,217,246,235,237,
-134,60,75,102,158,236,169,222,185,226,78,53,1,107,62,193,122,192,40,14,92,177,
-179,93,222,28,170,116,242,213,175,38,157,174,85,215,185,26,95,197,213,81,72,
-85,147,117,19,215,60,76,254,131,231,24,112,64,225,80,197,225,202,149,93,115,
-178,163,113,20,140,211,93,86,99,190,226,27,57,143,42,95,141,121,177,249,195,
-79,72,39,124,245,21,44,56,167,53,82,28,101,62,170,252,196,38,56,205,127,132,
-175,186,98,231,37,57,121,106,11,124,5,51,113,157,7,46,115,83,204,224,62,39,
-143,38,230,39,36,195,26,160,53,202,184,58,202,140,115,6,15,11,124,96,80,141,
-216,55,187,161,201,254,199,222,202,156,235,211,109,220,53,246,9,201,201,30,
-184,214,252,145,93,112,181,93,71,207,88,231,151,124,39,206,245,60,250,100,242,
-87,218,76,58,101,181,231,18,29,101,59,228,235,235,190,168,190,160,132,1,215,
-154,157,214,230,39,36,215,214,29,113,230,199,107,237,93,245,143,247,146,254,
-207,20,124,126,205,227,73,14,174,190,85,159,248,92,128,123,123,126,169,61,219,
-180,28,56,153,246,129,30,100,8,215,235,179,214,146,52,61,49,208,241,37,42,228,
-196,6,10,47,36,231,223,126,215,56,125,62,63,77,238,100,218,172,55,76,147,80,
-218,52,219,204,72,5,187,165,36,140,69,231,177,204,47,212,124,89,71,252,124,89,
-215,88,227,165,137,47,154,90,63,206,139,231,64,181,201,245,34,239,154,87,206,
-11,155,186,94,237,175,19,215,62,186,58,175,214,49,230,113,143,76,152,53,122,
-68,134,86,124,216,68,252,250,69,144,19,214,202,243,98,118,230,42,201,163,224,
-42,201,163,224,42,57,201,149,103,41,121,95,169,129,157,150,158,152,45,78,84,
-49,155,183,54,19,228,130,25,113,134,120,130,1,25,234,2,14,100,200,3,46,233,88,
-120,20,151,5,38,163,201,251,95,107,35,111,43,153,32,23,140,225,246,135,227,56,
-152,250,161,69,222,150,50,25,170,224,246,71,101,38,191,66,192,201,156,227,60,
-67,93,192,129,12,169,88,61,96,150,68,169,97,215,72,105,75,231,23,77,193,134,
-164,235,156,76,123,208,23,221,56,31,100,168,151,227,182,244,76,5,127,205,46,
-15,246,248,38,245,62,211,62,215,237,28,48,78,5,123,213,230,17,231,100,232,55,
-198,27,34,99,174,224,182,116,166,130,125,58,7,58,193,37,60,126,138,236,46,119,
-50,237,3,189,146,33,159,96,13,241,4,51,145,205,202,243,158,206,133,94,176,79,
-241,32,155,113,97,142,161,174,224,20,1,174,15,25,135,121,32,67,62,193,93,193,
-128,10,238,205,176,32,67,191,0,95,201,102,95,152,123,21,7,186,138,125,37,174,
-97,77,155,245,13,163,4,157,224,142,88,67,189,63,123,159,125,156,255,85,191,
-195,190,49,233,53,249,93,231,132,177,232,64,124,96,215,151,14,242,140,223,114,
-39,211,170,62,158,169,130,53,14,127,214,218,186,209,134,190,240,132,220,176,
-160,45,113,76,188,38,40,166,218,220,58,147,14,114,39,211,102,125,195,56,65,46,
-24,227,173,26,169,96,183,148,132,177,232,52,170,254,75,16,214,12,177,159,190,
-212,134,30,148,127,251,29,114,126,249,167,117,137,245,80,27,218,118,9,125,192,
-28,62,143,235,122,235,234,10,149,57,239,52,47,141,40,105,152,71,100,232,130,
-79,163,19,235,188,170,115,174,146,60,10,174,146,60,10,174,146,147,92,121,150,
-146,247,149,26,216,105,233,137,217,226,68,21,179,121,107,51,65,46,152,17,103,
-136,39,24,144,161,46,224,64,134,60,224,146,238,11,247,43,52,189,19,155,191,31,
-136,224,109,37,19,228,130,49,220,254,112,204,67,15,196,13,121,56,108,43,25,
-170,224,246,71,101,38,191,66,192,201,156,227,60,67,93,192,129,12,169,88,30,
-204,95,123,209,124,64,5,127,205,110,28,222,143,110,158,38,171,116,5,227,84,
-176,87,109,30,113,78,134,126,99,188,33,50,230,10,110,75,103,42,216,167,115,
-160,19,92,194,227,167,200,238,114,39,211,62,208,43,25,242,9,214,16,79,48,19,
-217,172,60,239,233,92,232,5,251,20,15,178,25,23,230,24,234,2,174,146,205,186,
-56,207,144,79,112,87,48,160,130,123,51,44,200,208,47,192,87,178,217,23,230,94,
-197,129,174,98,95,137,107,88,211,102,125,195,40,65,39,184,35,214,80,239,207,
-222,103,31,199,47,47,63,176,231,32,149,239,249,38,189,38,191,235,156,48,22,
-221,171,215,114,50,173,234,243,51,155,83,252,51,6,95,111,177,211,26,85,27,87,
-94,52,201,249,153,109,35,206,126,155,116,144,59,153,54,235,27,198,9,114,193,
-24,111,213,72,5,187,165,36,140,69,103,250,52,210,56,37,135,198,58,55,158,157,
-201,143,230,229,154,103,221,213,245,214,213,21,42,115,222,116,158,33,158,96,
-148,12,253,2,188,147,205,242,57,58,91,185,74,242,40,184,74,242,40,184,74,78,
-114,229,89,74,182,63,111,183,255,5,75,238,218,119,32,100,170,216,0,0,0,0,73,
-69,78,68,174,66,96,130 };
+0,0,14,189,0,0,14,189,1,71,251,144,173,0,0,0,24,116,69,88,116,83,111,102,116,
+119,97,114,101,0,112,97,105,110,116,46,110,101,116,32,52,46,49,46,49,99,42,
+156,75,0,0,29,72,73,68,65,84,120,94,237,93,61,200,181,73,82,29,4,67,83,13,69,
+16,76,76,6,4,17,131,5,215,81,16,49,80,55,88,21,113,13,12,92,208,100,50,5,13,
+84,12,6,68,5,153,104,52,48,144,85,80,16,35,17,99,127,34,19,77,196,68,35,5,81,
+76,68,228,218,167,78,215,173,83,63,125,239,115,191,239,27,118,132,173,203,121,
+223,167,171,78,87,87,87,87,247,243,60,247,157,111,247,189,219,123,183,27,240,
+94,17,215,79,54,23,229,60,226,65,174,240,174,112,32,202,123,196,125,198,121,
+102,119,81,222,43,220,173,186,235,118,51,201,196,159,100,226,89,107,208,95,
+145,171,253,148,247,105,113,183,106,20,229,157,184,143,108,144,43,125,31,245,
+135,188,202,219,205,167,242,46,253,190,43,142,139,115,175,250,188,194,133,188,
+194,133,92,225,43,231,42,111,171,142,162,220,183,229,159,244,46,207,236,42,87,
+184,87,56,147,104,191,171,125,63,205,62,87,121,85,94,233,115,133,119,213,223,
+85,30,68,185,175,242,183,234,37,249,52,198,121,215,62,159,241,212,254,136,231,
+242,105,242,30,113,175,112,32,159,53,222,219,232,171,205,229,100,127,85,239,
+242,204,14,185,106,175,156,103,253,32,39,142,235,171,237,164,119,81,251,137,
+227,242,166,220,173,74,114,213,190,155,73,62,75,182,147,120,159,79,163,223,21,
+142,202,171,124,151,123,191,123,239,130,170,201,173,64,213,228,86,160,106,78,
+122,197,172,37,246,149,58,216,83,179,201,169,126,76,76,229,24,110,183,79,22,
+62,66,75,197,152,153,187,45,33,198,120,192,217,90,250,207,188,49,62,72,226,
+125,225,126,133,248,32,159,168,125,119,105,178,108,53,46,200,181,121,222,110,
+255,181,240,37,209,249,213,151,22,254,117,225,3,177,65,62,88,128,30,246,237,
+117,244,251,115,11,136,33,235,87,235,138,88,175,11,253,140,149,121,47,229,105,
+155,154,24,51,115,183,37,139,177,50,47,113,67,211,109,46,102,61,216,139,109,
+236,15,49,214,235,188,173,61,75,225,191,149,223,55,229,220,91,2,211,103,238,
+237,246,75,169,21,192,190,42,218,147,95,67,229,159,252,46,92,142,3,186,170,
+189,192,123,41,78,160,248,76,253,31,197,208,109,185,85,237,101,156,132,39,92,
+139,137,159,35,7,112,73,250,234,27,152,252,75,123,236,147,91,29,53,62,32,183,
+136,87,107,107,193,236,213,255,48,255,59,148,27,247,136,140,26,135,218,20,53,
+23,143,114,247,36,111,46,119,221,3,223,137,119,130,246,47,113,37,212,113,196,
+214,198,121,7,62,19,248,201,26,109,85,63,142,174,33,170,191,139,235,107,19,93,
+146,56,192,80,143,165,69,116,94,110,57,234,124,78,57,172,188,139,243,184,204,
+91,45,155,47,63,207,245,30,231,180,30,117,14,157,51,251,124,162,119,49,235,3,
+59,196,24,131,253,174,169,49,241,185,235,43,246,219,117,101,30,46,171,21,125,
+53,191,53,167,222,191,142,85,252,54,59,177,71,203,2,189,112,12,219,52,74,226,
+214,90,24,106,32,181,52,174,26,51,63,108,85,191,143,250,229,49,179,237,234,
+120,181,95,129,203,106,101,102,245,121,66,237,23,243,251,112,193,158,249,167,
+220,217,152,170,81,84,159,207,248,14,237,87,109,142,170,201,173,64,213,228,86,
+160,106,110,183,111,177,171,170,87,204,90,98,95,169,3,155,60,196,180,161,31,
+139,185,114,12,159,229,23,205,159,177,159,241,34,247,155,171,45,246,221,165,
+137,177,132,103,248,218,139,102,19,99,190,57,119,91,178,24,43,243,18,55,52,
+221,230,98,86,183,127,238,126,69,160,157,53,187,87,22,99,189,206,219,218,179,
+20,254,91,249,125,83,206,110,161,222,254,123,1,135,233,182,218,199,91,16,212,
+230,127,218,85,200,135,233,6,17,92,191,242,47,117,92,58,159,99,86,225,129,14,
+212,53,154,249,31,38,14,121,117,108,204,79,247,34,196,175,42,247,163,195,188,
+48,54,30,72,222,95,208,252,161,127,250,226,106,243,99,63,103,155,95,157,206,1,
+248,199,56,177,30,28,99,154,67,59,51,150,190,230,204,215,110,138,29,240,156,
+78,121,116,27,207,155,0,124,230,135,51,7,127,250,28,84,56,159,190,239,32,149,
+251,201,147,218,66,60,42,81,51,125,254,115,45,192,170,177,240,97,164,214,249,
+84,179,53,86,151,92,3,186,190,75,35,57,63,213,11,252,198,60,2,157,207,249,215,
+53,1,15,177,219,120,27,189,198,184,14,145,131,224,241,12,112,13,185,83,76,104,
+67,255,190,240,188,78,170,48,30,237,29,62,92,56,143,90,23,188,103,59,183,251,
+113,244,90,155,253,113,125,125,158,16,206,1,227,8,207,22,106,201,214,68,94,10,
+207,192,177,84,62,105,227,162,205,43,157,115,206,31,208,125,185,228,53,225,60,
+52,223,92,203,90,167,157,199,28,246,121,112,190,252,60,215,71,190,167,243,66,
+247,207,180,102,179,207,39,122,23,179,62,176,67,140,81,236,210,3,107,80,247,
+82,63,203,168,75,231,42,100,217,194,55,235,19,107,246,81,203,41,251,157,206,
+246,223,95,248,237,133,94,3,196,30,45,11,244,194,49,108,211,40,137,203,90,192,
+216,136,247,131,86,43,81,163,61,110,214,16,99,133,70,227,96,14,188,198,242,
+122,135,158,245,169,57,138,241,16,79,206,3,99,224,158,131,70,199,203,113,250,
+62,166,127,234,125,238,209,7,96,236,24,7,18,115,9,125,31,11,96,222,242,89,85,
+115,151,91,191,178,128,88,128,143,77,87,125,198,28,128,186,231,99,46,224,57,
+43,248,25,85,147,91,129,170,225,207,111,92,248,229,133,239,218,237,137,247,
+151,11,223,211,244,138,89,75,236,43,117,108,11,4,49,109,232,199,98,174,28,131,
+111,186,210,197,152,153,187,45,33,198,120,192,217,90,250,207,188,49,62,72,226,
+177,96,176,128,216,228,239,215,98,217,93,154,24,75,120,134,171,243,196,198,
+202,7,144,90,171,13,242,252,112,35,239,107,47,154,75,66,211,109,46,102,117,59,
+15,69,228,150,7,105,205,255,208,31,98,172,215,121,91,123,150,194,127,43,191,
+111,194,185,95,177,150,255,109,97,190,153,0,165,54,247,111,220,88,234,75,20,
+196,15,239,122,160,163,102,235,141,55,223,196,8,240,168,235,123,164,243,251,
+58,66,248,64,161,218,238,11,63,99,172,176,160,239,233,165,235,206,181,156,6,
+255,211,124,209,196,111,222,196,235,77,174,172,139,197,196,207,196,129,15,247,
+233,192,88,56,19,105,83,11,16,99,199,141,159,128,79,196,152,99,7,24,11,248,
+118,70,110,128,15,63,167,151,120,157,175,207,191,157,245,75,220,143,174,173,
+243,169,211,27,52,251,212,90,64,27,252,92,95,225,91,227,192,3,97,125,33,240,
+171,88,63,180,123,125,37,187,173,13,45,167,122,137,184,66,235,115,171,47,128,
+136,177,114,49,71,136,174,19,199,210,47,86,113,77,174,230,4,215,31,213,47,96,
+151,192,23,114,194,57,106,60,202,197,220,163,23,16,188,94,179,234,211,121,189,
+46,200,131,160,62,251,62,9,30,230,232,115,14,127,125,61,48,30,230,9,206,113,
+92,89,39,32,114,250,188,110,137,90,127,232,199,24,53,223,189,94,122,14,225,23,
+254,107,253,161,174,144,63,219,243,11,81,55,207,121,185,22,8,214,38,63,207,
+245,145,187,233,188,248,173,5,175,21,204,183,214,249,236,243,137,222,197,172,
+15,236,16,99,20,251,110,33,46,158,149,97,135,64,143,249,68,125,113,143,32,95,
+128,105,205,143,250,230,186,114,223,244,218,69,206,249,172,153,245,200,29,244,
+120,33,233,118,162,107,168,109,22,11,234,32,137,27,53,130,223,24,55,175,11,
+107,207,99,203,95,90,212,92,104,125,51,7,168,83,214,182,214,52,251,69,206,213,
+39,199,139,188,107,77,178,95,248,212,241,34,78,214,31,181,62,55,232,201,156,
+239,1,140,255,124,141,62,181,159,239,193,95,92,0,239,203,11,185,126,48,22,175,
+48,62,98,198,188,208,143,241,105,78,0,230,12,245,81,239,145,0,250,98,207,230,
+154,202,156,64,213,228,86,160,106,248,243,23,22,254,105,1,107,78,139,114,128,
+219,237,91,23,254,167,233,21,252,249,195,11,63,176,175,129,111,179,223,187,
+165,142,119,121,14,155,57,174,2,117,33,1,223,116,89,219,185,177,48,129,186,24,
+19,199,253,87,109,110,5,180,197,226,141,205,175,133,13,196,85,70,141,11,184,
+58,79,244,205,253,213,218,125,235,166,124,204,155,95,52,193,139,214,25,83,156,
+106,119,212,113,129,220,10,84,159,64,110,5,42,119,94,235,121,252,26,171,114,
+38,63,58,86,212,0,31,90,106,13,92,205,195,21,222,137,163,120,151,126,95,229,
+196,149,223,92,112,40,70,237,241,227,92,72,173,205,104,43,143,92,236,141,124,
+240,59,114,12,16,63,200,43,151,123,172,239,211,196,31,207,43,242,16,131,237,
+17,23,99,117,206,181,56,129,105,108,90,56,150,114,129,115,142,252,42,106,81,
+237,244,143,113,48,30,56,241,176,88,247,78,89,23,139,137,159,137,19,223,162,
+135,21,253,176,254,172,1,237,7,196,156,113,163,245,151,3,88,240,27,250,233,69,
+115,62,31,117,46,213,18,243,117,13,174,79,47,99,60,251,50,16,15,124,247,191,
+60,245,62,136,131,121,87,110,228,34,215,67,241,39,235,30,126,208,230,231,206,
+91,146,236,210,239,84,47,145,159,208,134,143,199,92,95,15,64,115,207,181,152,
+31,242,152,47,2,215,253,203,183,92,139,208,224,55,218,245,75,32,157,31,16,57,
+239,53,91,235,35,124,42,143,113,2,115,14,28,93,195,177,117,206,64,248,115,204,
+188,184,66,92,168,7,206,191,242,0,218,117,189,78,123,20,62,88,39,39,222,106,
+73,14,145,119,250,238,241,97,60,173,211,57,63,186,6,68,196,161,60,31,151,159,
+231,122,141,77,245,64,206,49,199,87,141,219,115,237,156,245,171,165,98,214,7,
+118,136,49,138,125,183,230,58,155,242,130,156,151,60,155,31,245,77,14,242,59,
+125,153,2,159,176,61,122,209,252,120,172,169,208,228,186,225,71,121,125,242,
+34,137,251,187,246,19,243,225,23,134,104,171,157,115,65,126,250,158,165,45,98,
+209,53,170,253,248,169,253,80,155,185,142,105,139,252,62,178,233,120,172,19,
+228,16,177,96,92,180,99,124,175,185,90,71,252,235,34,124,58,31,188,199,235,
+203,126,190,135,188,79,175,81,228,138,156,73,78,245,230,103,175,207,5,2,29,
+226,241,92,199,253,56,122,59,190,123,225,79,154,246,118,251,247,133,31,219,
+173,64,110,65,240,243,31,23,190,207,90,183,219,55,47,156,120,93,175,184,221,
+126,221,126,82,126,117,1,218,255,88,248,38,231,168,3,75,52,196,180,161,135,
+224,167,38,242,244,159,53,129,227,15,51,46,125,19,70,33,161,232,93,242,67,14,
+57,88,136,42,167,23,77,141,111,90,220,234,171,126,67,140,159,234,3,133,201,13,
+162,60,114,235,60,49,143,252,159,6,144,247,86,255,233,236,2,198,161,239,204,
+155,95,52,195,47,14,49,23,223,32,46,211,183,111,62,46,250,249,154,244,28,146,
+139,159,154,39,198,55,215,67,245,201,135,153,185,30,174,174,53,198,198,218,
+192,23,98,140,27,25,253,104,108,249,63,99,234,99,228,155,160,174,11,53,113,
+160,101,30,242,201,252,100,94,196,219,125,97,108,206,63,218,117,124,248,85,14,
+230,146,215,161,143,237,60,29,27,253,225,71,133,126,157,19,89,65,28,238,15,
+126,128,167,47,52,11,209,79,121,228,66,15,187,105,84,150,166,250,213,241,201,
+161,101,246,95,248,134,186,239,200,67,158,56,23,71,223,159,41,206,132,217,103,
+31,155,224,88,170,1,52,103,217,230,87,81,35,106,167,127,140,131,189,131,117,
+139,24,249,81,110,90,23,203,223,153,3,63,186,134,0,114,4,61,127,107,63,32,207,
+57,234,131,62,161,175,15,173,144,20,15,4,215,11,62,175,105,28,234,67,115,202,
+233,157,231,130,235,13,196,54,157,111,181,22,98,30,249,124,192,156,114,190,
+129,146,79,25,51,214,111,224,45,73,118,233,119,154,155,231,7,118,215,146,219,
+191,112,137,92,82,131,177,240,144,130,47,4,160,135,221,215,61,159,207,124,48,
+2,208,23,118,128,126,250,190,119,30,124,250,154,79,220,184,162,61,206,49,126,
+194,202,56,181,6,35,79,202,139,94,39,187,193,18,187,100,107,34,135,181,14,98,
+222,64,228,175,159,11,248,233,185,195,95,48,200,171,254,200,213,115,22,188,
+211,127,133,129,57,195,238,50,249,211,22,250,244,26,5,248,133,41,108,92,7,214,
+200,244,165,92,173,251,168,7,229,173,94,150,63,126,158,235,153,59,174,161,234,
+129,200,113,228,87,237,186,62,89,143,53,70,46,199,216,92,208,22,91,179,67,140,
+33,118,97,51,103,61,79,94,215,81,95,88,67,157,195,210,54,223,88,63,247,89,215,
+146,253,251,125,196,245,142,186,182,132,95,69,92,212,118,46,215,120,146,41,
+191,220,67,30,179,218,57,23,214,17,52,58,86,228,130,107,174,115,101,191,168,
+85,237,71,91,212,92,239,135,152,224,243,241,139,166,218,34,127,24,211,37,206,
+26,198,63,125,121,20,115,139,107,230,33,88,211,249,135,56,240,252,10,46,251,
+87,78,212,60,184,120,54,69,174,192,103,76,181,6,52,95,234,55,98,194,53,57,209,
+199,175,190,115,225,143,22,254,97,225,199,239,90,199,237,246,249,133,63,182,
+43,125,225,236,188,31,89,248,235,221,250,243,133,95,179,235,206,227,85,213,43,
+110,183,255,93,248,246,221,250,67,40,150,252,222,194,189,159,58,176,141,4,49,
+109,232,33,152,180,47,72,20,142,114,200,67,146,248,226,65,13,126,247,195,131,
+122,240,98,145,251,98,68,95,106,48,46,218,211,203,135,23,142,107,184,96,202,
+225,225,12,95,44,222,249,80,198,166,70,145,64,131,54,231,162,60,114,235,60,
+209,158,30,6,222,230,69,51,226,233,155,230,209,139,166,111,10,104,144,95,136,
+231,6,246,105,61,60,183,62,127,111,79,15,132,156,107,104,48,6,184,211,3,167,
+250,132,38,230,148,121,17,23,53,62,143,105,173,49,54,199,115,109,216,16,139,
+142,151,15,133,168,1,230,190,175,87,216,168,129,31,248,171,55,75,93,39,104,
+162,95,112,208,151,7,51,53,254,114,236,53,143,121,100,191,140,15,122,228,9,
+253,250,65,123,101,236,124,51,11,190,250,137,195,209,199,195,117,172,101,223,
+143,240,3,155,74,255,102,148,92,230,108,181,170,24,59,115,211,154,25,135,150,
+62,175,224,171,156,246,40,230,164,194,121,101,206,61,206,13,228,194,101,170,
+189,58,182,202,244,226,16,185,207,54,191,58,205,209,235,14,130,152,204,98,185,
+233,249,75,245,112,129,131,188,184,207,24,159,186,105,191,235,250,128,143,124,
+67,135,62,208,231,216,217,39,197,3,193,245,6,235,77,53,64,94,11,248,230,94,
+121,192,83,65,123,129,115,155,31,50,84,124,156,156,43,244,163,13,194,122,129,
+165,60,88,200,120,154,191,236,11,40,246,22,167,114,1,254,196,248,158,239,56,
+67,234,156,120,86,232,90,226,26,136,117,225,248,60,67,242,126,246,43,175,179,
+123,141,237,143,183,32,248,9,95,152,7,190,248,160,191,206,245,43,112,185,118,
+97,81,30,228,94,31,27,145,39,229,69,175,147,157,200,45,204,133,249,171,103,24,
+207,60,95,95,8,99,236,103,157,231,5,246,184,174,107,64,174,182,48,246,244,28,
+128,117,209,231,5,248,237,231,81,244,138,117,167,54,251,139,251,132,202,244,2,
+133,113,234,184,211,121,201,218,172,227,156,244,26,159,234,1,222,123,60,103,
+211,151,62,97,203,122,196,136,156,100,159,244,23,168,107,181,90,85,140,33,246,
+125,21,53,212,215,59,246,140,235,226,254,136,156,205,251,131,231,5,108,227,
+151,6,67,44,119,189,139,89,179,93,231,172,123,121,154,123,159,188,72,226,62,
+203,99,212,20,230,203,168,220,150,159,21,242,92,153,131,200,145,246,163,205,
+207,142,124,134,113,60,244,195,252,166,191,90,198,122,105,93,211,230,53,4,59,
+160,53,142,56,78,127,76,65,125,65,208,23,95,200,145,27,210,215,145,115,128,
+111,140,193,113,42,39,114,139,249,0,24,11,190,17,231,244,242,138,49,157,23,
+235,75,29,243,200,49,63,150,62,63,177,240,7,11,152,195,207,47,208,226,246,224,
+249,213,119,44,252,197,194,223,46,124,49,113,128,219,237,207,22,126,118,183,
+190,119,1,255,116,234,235,6,30,175,170,94,209,53,95,127,191,222,26,117,176,
+203,115,60,88,240,211,147,237,114,122,9,65,18,85,11,93,125,80,7,199,19,122,26,
+51,113,54,232,95,53,0,23,171,202,87,18,39,10,134,55,202,94,136,240,129,133,
+118,77,108,16,229,1,125,158,232,135,254,245,5,234,77,95,52,17,35,253,193,210,
+11,245,217,95,52,189,112,99,14,181,157,251,85,30,112,202,117,229,249,166,159,
+234,161,114,49,14,184,117,222,175,172,117,205,125,228,128,254,177,17,121,19,
+135,86,15,176,168,1,196,53,253,123,183,176,81,51,207,45,14,101,143,153,49,233,
+129,72,14,226,4,224,15,28,63,220,230,60,48,62,159,67,28,158,186,254,225,215,
+199,230,181,142,29,87,17,63,218,234,135,135,163,143,229,117,31,237,236,15,2,
+155,174,167,251,126,248,210,80,101,217,171,223,216,59,155,143,223,73,255,128,
+111,208,53,14,158,230,136,168,60,137,179,128,235,89,181,211,216,4,199,82,13,
+160,57,203,54,191,138,122,83,123,228,214,255,58,21,243,224,71,185,105,93,44,
+127,143,57,0,214,24,191,57,79,178,112,61,237,225,58,103,240,209,255,167,22,
+160,207,177,179,79,138,7,130,235,5,159,215,52,14,244,42,167,7,123,246,95,45,
+23,92,111,112,62,125,95,107,45,120,252,200,73,206,85,60,80,57,15,210,94,92,
+101,76,204,145,235,135,182,250,2,138,93,250,49,30,229,2,252,169,107,21,185,
+175,181,203,179,2,28,220,43,208,39,94,76,124,45,9,206,91,247,126,204,19,113,
+248,189,198,114,154,120,64,92,121,62,200,3,248,97,43,124,98,60,207,53,231,172,
+60,32,199,10,68,158,148,23,189,78,118,130,63,145,3,172,235,125,236,54,151,136,
+209,193,88,31,215,75,212,108,61,19,23,108,130,75,182,102,142,51,251,3,230,125,
+16,241,197,186,163,205,79,240,104,143,26,230,184,220,211,202,99,141,248,186,
+65,144,119,230,94,121,203,187,205,161,142,115,210,51,174,201,143,142,201,249,
+214,53,224,125,167,159,197,39,125,172,171,75,61,59,44,70,21,232,238,246,200,
+233,57,38,142,129,124,235,186,249,85,216,168,13,11,231,10,159,239,246,69,51,
+175,153,74,187,39,109,55,163,20,238,214,82,208,22,27,36,214,212,216,246,185,
+247,221,87,136,43,159,175,204,65,156,51,218,143,54,228,141,231,153,246,227,56,
+220,43,208,232,186,123,45,232,62,112,13,159,127,48,22,98,113,173,215,63,190,8,
+163,207,83,125,17,190,166,184,135,193,23,230,14,31,152,127,126,222,200,123,18,
+118,60,151,229,26,100,95,125,55,82,249,112,168,55,214,140,142,73,11,243,203,
+107,230,52,250,252,134,253,196,76,194,83,246,11,228,214,247,47,252,243,194,
+223,36,45,112,187,253,144,180,128,31,92,248,134,164,1,252,170,234,21,179,150,
+216,87,234,96,151,224,88,132,88,20,46,56,129,235,233,97,161,22,192,204,37,135,
+133,233,232,7,76,231,184,127,213,0,62,70,214,102,127,44,250,88,88,45,122,160,
+251,136,13,162,60,160,207,19,253,152,159,204,123,147,23,77,108,24,124,187,16,
+55,146,94,168,255,95,95,52,35,190,204,123,101,173,107,238,35,7,60,132,0,140,
+131,141,159,215,36,106,128,49,244,26,8,27,53,243,220,178,159,120,224,214,26,
+206,245,134,23,6,196,12,191,244,135,111,171,234,131,11,251,128,131,181,159,95,
+52,121,96,250,216,63,186,0,255,87,254,90,9,123,112,152,43,216,38,201,121,3,24,
+23,198,100,76,4,215,77,121,128,235,179,150,232,251,60,246,142,242,60,246,154,
+163,194,31,207,43,242,238,49,184,24,235,192,1,140,195,107,142,237,45,199,52,
+54,45,167,60,68,206,178,205,175,188,62,106,174,163,238,162,30,48,198,233,33,
+233,190,46,22,83,159,103,93,59,204,47,254,105,64,232,166,61,92,215,199,99,115,
+244,135,127,207,95,214,2,24,11,115,153,206,84,159,111,104,235,92,129,178,102,
+2,207,211,179,127,163,233,241,247,124,114,111,41,198,245,147,117,199,124,96,7,
+143,89,23,222,146,154,119,7,227,81,13,16,87,158,191,200,99,205,5,99,117,255,
+200,27,184,190,70,232,227,253,153,83,141,45,206,38,174,5,57,184,110,15,104,
+167,185,154,190,251,12,63,155,3,73,60,160,175,53,174,161,203,251,32,122,197,
+216,217,78,228,185,152,118,28,183,175,239,236,151,190,38,121,180,102,192,201,
+31,230,231,245,7,196,254,86,30,227,11,155,91,234,60,180,46,136,217,95,220,7,
+28,136,175,159,55,203,251,195,124,149,154,88,130,241,120,223,81,61,192,62,94,
+123,221,231,106,189,52,150,235,29,213,190,90,85,140,225,118,246,207,251,80,
+237,0,237,200,159,174,155,50,34,223,253,188,224,30,59,196,101,218,65,239,98,
+214,108,215,57,71,92,104,247,49,32,136,107,146,122,255,218,35,82,208,22,155,
+190,192,177,238,212,30,117,68,187,62,107,196,190,239,235,77,91,228,94,251,113,
+188,216,247,58,55,206,63,246,146,62,3,104,237,81,227,128,47,72,95,39,66,91,62,
+79,248,192,125,16,58,248,133,62,239,221,88,11,240,225,155,115,85,14,231,18,
+253,131,75,70,141,133,54,32,114,195,107,156,59,240,209,247,51,127,242,223,101,
+222,110,255,178,240,69,211,185,61,243,240,18,249,87,11,127,183,240,147,166,
+155,121,29,85,115,210,43,102,45,177,175,212,193,46,193,161,8,153,0,36,15,45,
+252,134,76,15,37,72,210,253,70,179,0,46,219,153,135,196,66,239,197,130,223,95,
+46,28,244,141,135,109,254,70,123,122,0,196,162,177,96,169,65,223,28,31,139,30,
+62,120,208,106,209,3,140,93,125,192,39,199,87,94,112,163,144,56,30,251,102,
+222,219,252,167,179,145,187,30,235,87,243,69,19,122,142,77,204,107,12,80,175,
+92,246,157,95,30,174,174,53,227,82,109,216,248,191,8,198,22,126,51,23,110,143,
+26,160,190,199,129,60,32,102,196,3,13,126,67,30,61,16,224,75,1,206,177,223,
+132,60,175,224,120,92,224,162,221,255,242,194,3,203,231,135,177,89,83,122,8,
+231,67,31,232,28,206,179,238,137,124,163,138,248,25,123,0,113,114,111,170,54,
+230,226,243,240,254,211,26,121,30,213,55,248,104,215,154,143,121,134,118,158,
+215,137,95,57,228,97,254,54,190,139,177,50,103,138,19,64,123,154,87,26,219,
+124,210,194,177,148,11,104,206,84,143,120,121,197,126,189,14,61,183,24,15,26,
+228,28,251,161,127,115,222,215,165,231,163,115,220,159,206,27,215,211,153,62,
+173,143,247,71,238,166,125,239,118,204,207,181,158,235,94,247,128,204,215,197,
+88,157,55,173,153,231,139,186,249,198,174,124,196,7,31,245,91,118,140,175,188,
+113,253,44,54,182,224,7,118,240,122,188,177,159,53,127,49,182,114,23,196,47,
+226,0,135,60,232,170,239,126,14,212,249,97,76,220,235,122,108,145,47,95,159,
+200,95,169,197,211,92,77,159,125,250,186,120,205,6,30,239,97,31,123,252,171,
+208,190,138,177,179,157,224,220,181,214,136,121,92,229,49,111,125,255,105,43,
+226,171,60,128,118,229,77,127,33,173,185,241,245,205,243,65,63,114,225,103,
+206,51,160,253,169,153,107,42,206,25,224,156,103,231,205,249,234,113,178,174,
+223,27,243,145,199,236,123,241,60,214,60,135,197,82,65,91,108,205,14,49,134,
+219,153,83,204,3,115,231,90,169,29,208,156,135,158,190,216,66,108,124,110,212,
+184,233,155,168,243,241,254,252,52,189,139,89,179,221,56,251,42,213,194,254,
+40,175,79,94,164,112,183,150,130,182,216,124,46,177,143,212,206,53,155,235,39,
+242,203,243,71,251,209,134,216,121,134,246,126,145,215,171,54,214,30,247,45,
+53,128,199,6,161,190,174,71,156,151,17,171,142,161,215,206,4,152,15,244,1,112,
+205,177,149,195,252,96,158,176,193,23,94,94,225,111,206,181,230,132,126,33,
+168,125,252,209,2,191,33,249,62,25,189,129,207,45,252,233,194,244,151,74,252,
+5,243,239,23,126,122,33,44,202,1,114,43,80,53,39,189,98,214,18,251,74,29,88,
+82,32,166,13,61,4,9,118,193,98,176,224,148,67,30,18,237,255,22,13,130,135,141,
+92,96,0,11,201,19,12,129,191,188,192,228,232,184,224,96,236,233,1,16,63,49,
+182,11,11,73,57,44,134,40,166,90,136,44,16,47,86,72,124,227,175,60,114,225,
+159,27,146,192,92,250,28,222,254,127,12,200,231,159,231,252,213,125,209,172,
+121,226,141,168,174,49,185,240,137,255,209,36,23,230,168,230,254,181,181,174,
+185,15,95,61,182,124,40,178,6,148,147,15,140,30,199,92,235,249,208,98,141,163,
+205,79,229,32,94,206,187,246,233,53,168,92,143,179,254,47,168,249,149,239,31,
+252,206,55,116,198,131,49,84,56,102,230,240,198,190,52,182,239,105,1,16,71,
+206,13,107,196,247,181,203,233,165,1,63,235,90,204,103,65,204,67,37,214,183,
+62,168,156,248,202,33,15,62,48,15,155,27,100,233,171,47,191,2,79,133,53,173,
+92,128,99,223,215,210,124,210,194,177,148,11,156,247,155,215,24,199,57,159,69,
+92,91,194,231,93,207,130,105,93,242,63,27,208,56,168,153,252,35,7,87,95,52,1,
+240,79,121,194,207,41,46,142,87,215,148,125,238,241,184,24,171,243,240,179,
+214,22,36,246,97,207,231,189,22,4,104,115,94,174,233,251,31,210,30,204,45,54,
+182,48,30,242,138,185,246,120,251,121,227,50,189,84,169,95,239,195,248,160,
+171,190,163,229,117,161,107,249,184,191,174,93,244,193,92,144,195,84,3,167,
+185,154,190,251,156,164,215,8,127,42,31,57,159,234,194,175,98,236,108,39,122,
+126,33,156,187,242,184,190,58,46,57,165,94,108,114,75,182,198,115,121,250,255,
+209,212,26,135,239,62,15,142,235,249,133,204,103,33,235,37,237,55,139,131,159,
+234,79,235,244,116,182,214,61,56,239,63,198,198,231,162,172,7,127,90,63,247,
+219,207,11,248,102,108,156,67,31,11,243,194,88,245,76,68,12,240,153,245,171,
+183,10,218,98,107,118,136,49,220,30,47,38,172,49,235,97,31,111,65,48,31,196,
+171,243,164,47,182,34,102,205,49,245,232,247,209,84,187,214,159,159,166,119,
+49,107,182,27,103,95,69,92,212,54,238,118,51,74,225,110,45,5,109,177,121,77,
+97,189,123,13,211,22,177,232,62,168,253,212,111,244,227,189,71,115,71,91,212,
+221,35,155,142,199,61,226,121,87,65,12,170,207,247,73,214,37,124,198,121,77,
+248,62,154,247,16,99,209,51,163,127,145,68,223,35,158,228,26,130,223,106,13,
+232,26,84,27,241,249,166,185,221,126,71,90,129,170,201,173,64,213,156,244,138,
+89,75,236,43,117,96,73,129,152,54,244,16,109,17,211,161,203,34,232,168,155,
+112,90,152,234,239,180,120,211,184,185,21,208,86,245,87,99,82,27,17,69,89,45,
+167,121,214,216,208,206,58,191,154,125,191,234,23,173,170,143,214,25,147,63,
+181,59,42,15,200,173,64,205,39,224,7,76,214,94,171,7,191,57,84,237,20,171,95,
+77,54,29,171,142,83,231,55,199,49,229,33,183,66,171,150,108,155,80,243,48,197,
+15,204,115,192,1,133,67,21,135,43,71,118,203,201,143,206,163,112,92,238,186,
+58,231,43,177,57,114,43,227,234,156,23,44,30,126,66,59,241,107,172,128,240,92,
+86,43,241,76,119,111,21,60,241,9,164,254,143,248,213,86,252,188,146,147,167,
+190,128,43,156,9,181,31,80,250,166,57,3,83,159,220,234,224,39,107,165,229,178,
+90,15,121,5,56,103,240,176,192,7,6,181,200,28,204,111,88,114,252,177,183,50,
+202,250,52,31,142,26,239,201,31,80,215,124,225,232,23,168,190,91,239,39,208,
+254,101,77,19,202,122,158,98,50,253,27,250,148,171,12,245,231,26,109,85,63,
+142,174,33,42,255,133,245,133,36,14,48,172,89,105,17,252,132,230,226,184,19,
+207,226,120,83,127,167,53,169,254,120,47,233,255,76,193,251,215,60,158,244,64,
+141,173,198,196,135,124,220,219,243,75,237,217,167,229,192,197,172,15,236,16,
+99,184,93,159,181,150,166,217,201,137,151,168,208,147,27,44,188,144,228,191,
+126,123,204,64,157,167,247,231,167,233,93,204,154,237,198,105,26,106,155,101,
+187,25,165,112,183,150,130,182,216,124,46,243,11,53,95,214,49,127,190,172,235,
+92,227,165,137,47,154,186,126,236,55,191,104,114,188,200,187,230,149,253,194,
+167,142,87,235,235,132,90,71,87,251,213,117,140,126,220,35,19,103,181,30,137,
+177,149,31,62,49,127,253,34,200,5,99,229,126,209,59,163,106,114,43,80,53,185,
+21,168,154,147,94,49,107,137,125,165,14,118,90,122,98,182,58,73,229,108,108,
+107,22,232,133,51,242,140,241,132,3,49,86,230,205,196,37,133,183,181,20,180,
+197,6,193,226,114,129,9,20,121,255,207,106,136,237,37,11,244,194,49,222,254,
+176,29,7,83,63,180,136,237,41,139,177,10,207,62,188,74,250,43,98,189,46,244,
+51,86,230,29,7,48,102,225,46,185,191,104,170,24,51,115,183,133,178,181,243,
+139,166,112,67,211,109,46,102,61,216,139,109,236,15,49,214,235,188,173,61,75,
+225,95,243,203,131,61,190,73,189,247,180,207,117,63,7,142,75,225,94,245,105,
+216,166,81,140,157,249,219,50,139,177,159,240,141,145,57,151,120,91,61,74,229,
+110,108,107,23,216,132,151,248,248,45,186,187,222,197,172,15,236,42,198,124,
+194,53,198,19,206,36,214,43,247,123,218,23,118,225,26,182,233,40,214,227,66,
+31,99,93,225,37,198,66,125,200,88,173,147,24,243,9,175,112,142,206,42,15,173,
+147,24,51,115,207,228,37,198,206,252,109,185,38,214,251,66,223,194,123,37,166,
+173,237,82,120,71,98,229,161,165,98,214,108,55,108,115,147,101,171,252,109,
+201,98,44,225,109,117,147,202,3,182,41,137,177,50,111,91,178,24,235,179,192,
+243,255,212,239,176,111,76,123,77,127,183,185,160,45,54,8,31,216,245,165,131,
+152,249,91,239,98,86,181,199,51,85,64,231,225,207,90,219,54,250,208,23,158,
+208,27,23,178,53,206,209,87,150,205,56,199,109,218,65,239,98,214,108,111,28,
+23,232,133,99,216,166,81,10,119,107,41,104,139,77,103,213,255,8,194,53,195,
+220,79,95,106,195,14,201,127,253,14,61,191,252,211,117,137,241,176,54,244,237,
+26,198,128,62,124,30,215,241,214,213,21,41,125,222,170,95,106,81,211,56,143,
+196,216,133,159,90,39,104,191,106,115,84,77,110,5,170,38,183,2,85,115,210,43,
+102,45,177,175,212,193,78,75,79,204,86,39,169,156,141,109,205,2,189,112,70,
+158,49,158,112,32,198,202,188,153,184,164,240,182,150,130,182,216,32,248,137,
+162,119,97,241,247,3,17,216,94,178,64,47,28,227,237,15,219,60,244,32,220,144,
+135,195,182,138,177,10,207,62,188,74,250,43,98,189,46,244,51,86,230,29,7,48,
+102,225,46,249,218,139,230,3,41,252,107,126,227,240,126,116,243,52,93,149,43,
+28,151,194,189,234,211,176,77,163,24,59,243,183,101,22,99,63,225,27,35,115,46,
+241,182,122,148,202,221,216,214,46,176,9,47,241,241,91,116,119,189,139,89,31,
+216,85,140,249,132,107,140,39,156,73,172,87,238,247,180,47,236,194,53,108,211,
+81,172,199,133,62,198,186,192,171,98,189,114,191,109,233,98,204,39,188,194,57,
+58,171,60,180,78,98,204,204,125,56,55,99,103,254,182,92,19,235,125,161,111,
+225,189,18,211,214,118,41,188,35,177,242,208,82,49,107,182,27,182,185,201,178,
+85,254,182,100,49,150,240,182,186,73,229,1,219,148,196,88,153,183,45,89,140,
+245,89,224,241,203,203,247,110,95,88,80,253,238,111,218,107,250,187,205,5,109,
+177,189,241,88,46,102,85,123,126,102,115,137,127,198,224,227,45,184,172,86,
+245,113,229,69,147,200,207,108,155,113,142,219,180,131,222,197,172,217,222,56,
+46,208,11,199,176,77,163,20,238,214,82,208,22,155,217,83,75,231,41,57,52,104,
+95,172,163,218,30,245,203,107,158,109,87,199,91,87,87,164,244,121,167,253,140,
+241,132,163,98,236,23,248,46,214,203,251,104,111,69,213,228,86,160,106,114,43,
+80,53,39,189,98,214,18,246,243,118,251,63,227,27,138,9,123,111,123,255,0,0,0,
+0,73,69,78,68,174,66,96,130 };
+
static const char*
default_charset = R"( abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.!?;:-_/|\!'"+=*()[]{}&%$#@<>^`~)";