summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/3rd-party/Luax/luax_class.hpp39
-rw-r--r--source/3rd-party/Luax/luax_class.inl10
-rw-r--r--source/3rd-party/Luax/luax_enum.cpp2
-rw-r--r--source/3rd-party/Luax/luax_enum.h3
-rw-r--r--source/3rd-party/Luax/luax_reftable.cpp10
-rw-r--r--source/3rd-party/Luax/luax_runtime.cpp36
-rw-r--r--source/3rd-party/Luax/luax_runtime.h15
-rw-r--r--source/3rd-party/Luax/luax_state.cpp28
-rw-r--r--source/3rd-party/Luax/luax_state.h71
-rw-r--r--source/3rd-party/Luax/luax_vm.cpp (renamed from source/3rd-party/Luax/luax_context.cpp)10
-rw-r--r--source/3rd-party/Luax/luax_vm.h (renamed from source/3rd-party/Luax/luax_context.h)10
-rw-r--r--source/3rd-party/uuid4/uuid4.c90
-rw-r--r--source/3rd-party/uuid4/uuid4.h22
-rw-r--r--source/Asura.Editor/widgets/binding/_button.cpp2
-rw-r--r--source/Asura.Editor/widgets/button.h8
-rw-r--r--source/libs/asura-lib-core/graphics/binding/_image.cpp4
-rw-r--r--source/libs/asura-lib-core/graphics/image.h9
-rw-r--r--source/libs/asura-lib-core/graphics/shader.h2
-rw-r--r--source/libs/asura-lib-core/input/mouse.h4
-rw-r--r--source/libs/asura-lib-core/window/window.cpp (renamed from source/libs/asura-lib-core/graphics/window.cpp)0
-rw-r--r--source/libs/asura-lib-core/window/window.h (renamed from source/libs/asura-lib-core/graphics/window.h)4
-rw-r--r--source/libs/asura-lib-core/window/window_impl_glew.cpp (renamed from source/libs/asura-lib-core/graphics/window_impl_glew.cpp)0
-rw-r--r--source/libs/asura-lib-core/window/window_impl_glew.h (renamed from source/libs/asura-lib-core/graphics/window_impl_glew.h)0
-rw-r--r--source/libs/asura-lib-core/window/window_impl_glut.cpp (renamed from source/libs/asura-lib-core/graphics/window_impl_glut.cpp)0
-rw-r--r--source/libs/asura-lib-core/window/window_impl_glut.h (renamed from source/libs/asura-lib-core/graphics/window_impl_glut.h)0
-rw-r--r--source/libs/asura-lib-core/window/window_impl_sdl.cpp (renamed from source/libs/asura-lib-core/graphics/window_impl_sdl.cpp)0
-rw-r--r--source/libs/asura-lib-core/window/window_impl_sdl.h (renamed from source/libs/asura-lib-core/graphics/window_impl_sdl.h)0
-rw-r--r--source/libs/asura-lib-openal/sound.h8
-rw-r--r--source/libs/asura-lib-openal/sound_decode_task.cpp0
-rw-r--r--source/libs/asura-lib-openal/sound_decode_task.h25
-rw-r--r--source/libs/asura-lib-openal/sound_decoder.cpp29
-rw-r--r--source/libs/asura-lib-openal/sound_decoder.h7
-rw-r--r--source/libs/asura-lib-utils/io/binding/_data_buffer.cpp18
-rw-r--r--source/libs/asura-lib-utils/io/binding/_file.cpp12
-rw-r--r--source/libs/asura-lib-utils/io/binding/_file_system.cpp22
-rw-r--r--source/libs/asura-lib-utils/io/binding/_io_task.cpp18
-rw-r--r--source/libs/asura-lib-utils/io/data_buffer.cpp10
-rw-r--r--source/libs/asura-lib-utils/io/data_buffer.h3
-rw-r--r--source/libs/asura-lib-utils/io/file.cpp10
-rw-r--r--source/libs/asura-lib-utils/io/io_task.cpp25
-rw-r--r--source/libs/asura-lib-utils/io/io_task.h26
-rw-r--r--source/libs/asura-lib-utils/scripting/lua_env.h28
-rw-r--r--source/libs/asura-lib-utils/threading/binding/_thread.cpp21
-rw-r--r--source/libs/asura-lib-utils/threading/mutex.h16
-rw-r--r--source/libs/asura-lib-utils/threading/task.cpp12
-rw-r--r--source/libs/asura-lib-utils/threading/task.h11
-rw-r--r--source/libs/asura-lib-utils/threading/thread.cpp14
-rw-r--r--source/libs/asura-lib-utils/threading/thread.h52
-rw-r--r--source/libs/asura-lib-utils/threading/thread_impl_posix.cpp9
-rw-r--r--source/libs/asura-lib-utils/threading/thread_impl_win32.cpp8
-rw-r--r--source/libs/asura-lib-utils/threading/thread_task.cpp0
-rw-r--r--source/libs/asura-lib-utils/threading/thread_task.h44
-rw-r--r--source/libs/asura-lib-utils/type.h8
-rw-r--r--source/libs/asura-lib-utils/utils_module.cpp1
-rw-r--r--source/libs/asura-lib-utils/utils_module.h1
-rw-r--r--source/tests/02-luax/main.cpp10
-rw-r--r--source/tests/05-physfs/main.cpp37
57 files changed, 645 insertions, 219 deletions
diff --git a/source/3rd-party/Luax/luax_class.hpp b/source/3rd-party/Luax/luax_class.hpp
index cfac2a5..99ac381 100644
--- a/source/3rd-party/Luax/luax_class.hpp
+++ b/source/3rd-party/Luax/luax_class.hpp
@@ -13,7 +13,8 @@ namespace Luax
///
/// RegisterLuaxClass עķͳԱö١ȵclass table
- /// LuaxGetFactoryName ùͬʱעʱעΪsingletonͨʱ
+ /// LuaxGetFactoryName ùͬʱעʱעΪsingletonͨ
+ /// ʱ
///
#define LUAX_DECL_FACTORY(type) \
static void RegisterLuaxClass(Luax::LuaxState&);\
@@ -69,8 +70,9 @@ namespace Luax
T* self = state.GetUserdata<T>(1);
///
- /// ࣬Ϊʵֶ̬ҪЩӿڵⲿҪ̳д֮࣬оͻöӦʵķע̳д
- /// ʱʵķʵLuaxNativeClassУʵֻᵼ¶ԡ
+ /// ࣬Ϊʵֶ̬ҪЩӿڵⲿҪ̳д֮࣬оͻ
+ /// öӦʵķע̳дʱʵķʵLuaxNativeClassУʵֻ
+ /// ¶ԡ
///
class ILuaxNativeAccessor
{
@@ -88,7 +90,8 @@ namespace Luax
};
///
- /// Ҫ¶luanative classҪ̳дࡣͨluaʵҪȷüȷԣڶ߳Ҫȷͷš
+ /// Ҫ¶luanative classҪ̳дࡣͨluaʵҪȷüȷԣ
+ /// ߳Ҫȷͷš
///
template<class T>
class LuaxNativeClass : public virtual ILuaxNativeAccessor
@@ -98,8 +101,9 @@ namespace Luax
static bool IsTypeOf(ILuaxNativeAccessor);
///
- /// userdataΪkeyref tableuserdataһãάuserdataڡȽmember ref
- /// ʵᱻαͬʵõƵЩʵ壬luaƵĵgc⡣
+ /// userdataΪkeyref tableuserdataһãάuserdataڡ
+ /// Ƚmember refʵᱻαͬʵõƵЩʵ壬
+ ///luaƵĵgc⡣
///
template<class U> void LuaxRetain(LuaxState& state, U* userdata);
@@ -111,8 +115,8 @@ namespace Luax
bool PushLuaxMemberRef(LuaxState& state, int refID) override;
///
- /// userdata pushջûгʼmUserdataʼúԪѳʼõuserdataջһá
- /// һnativeȨƽluaƵķ
+ /// userdata pushջûгʼmUserdataʼúԪѳʼõ
+ /// userdataջһáһnativeȨƽluaƵķ
///
bool PushLuaxUserdata(LuaxState& state);
bool PushLuaxMemberTable(LuaxState& state);
@@ -143,8 +147,8 @@ namespace Luax
static void PushLuaxClassTable(LuaxState& state);
///
- /// ȡַҪַֻͨڶϴʵõջϺ;̬ıȡַ֤ü׼ȷ
- /// ҪãʹôݶǴݵַ
+ /// ȡַҪַֻͨڶϴʵõջϺ;̬ı
+ /// ȡַ֤ü׼ȷҪãʹôݶǴݵַ
///
void* operator &();
@@ -158,17 +162,18 @@ namespace Luax
///
static LuaxStrongRef mClassTable;
///
- /// ǵsingletonùϵԱ֤ᱻͨref tableijԱȫڵģ
- /// ֱ_LUAX_STRONGREF_TABLEuserdataLuaxRetain\LuaxReleasemember refʱ͹ʵͬ
- /// Ǵref tableģtable_LUAX_STRONGREF_TABLE
+ /// ǵsingletonùϵԱ֤ᱻͨref table
+ /// ijԱȫڵģֱ_LUAX_STRONGREF_TABLEuserdata
+ /// LuaxRetain\LuaxReleasemember refʱ͹ʵͬǴref table
+ /// ģtable_LUAX_STRONGREF_TABLE
///
static LuaxStrongRef mSingletonRefTable;
///
/// ͨuserdataõ:
- /// 1: ref table
- /// 2: member table
- /// 3: class table
+ /// 1: ref table
+ /// 2: member table
+ /// 3: class table
///
LuaxWeakRef mUserdata;
@@ -193,7 +198,7 @@ namespace Luax
#endif
};
- //--------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
#if LUAX_ENABLE_PLAIN_CLASS
///
diff --git a/source/3rd-party/Luax/luax_class.inl b/source/3rd-party/Luax/luax_class.inl
index 7ee3de9..d1c8c4b 100644
--- a/source/3rd-party/Luax/luax_class.inl
+++ b/source/3rd-party/Luax/luax_class.inl
@@ -1,7 +1,7 @@
namespace Luax
{
- //----------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
// ӿ
///
@@ -17,7 +17,7 @@ namespace Luax
return 1;
}
- //----------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
///
/// עṤ͵еԱ
@@ -205,8 +205,8 @@ namespace Luax
assert(!T::IsLuaxClassSingleton());
assert(!mUserdata);
- // userdataջ
- state.PushPtrUserdata(this);
+ // userdataջעַҪתΪT*ֱthisܻᵼ¶ؼ̳еɥʧ̬
+ state.PushPtrUserdata(static_cast<T*>(this));
lua_newtable(state); // ref table޷luaʣC
lua_newtable(state); // member tableluaдĶԱ
@@ -315,7 +315,7 @@ namespace Luax
}
}
- //--------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
///
/// ͷŹʵ
diff --git a/source/3rd-party/Luax/luax_enum.cpp b/source/3rd-party/Luax/luax_enum.cpp
index b054d98..60dd552 100644
--- a/source/3rd-party/Luax/luax_enum.cpp
+++ b/source/3rd-party/Luax/luax_enum.cpp
@@ -34,7 +34,7 @@ namespace Luax
return luaL_error(L, "Enum called \"%s\" is readonly.", name);
}
- //--------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
#if LUAX_ENABLE_PLAIN_ENUM
int LuaxPlainEnum::registry(lua_State* L)
{
diff --git a/source/3rd-party/Luax/luax_enum.h b/source/3rd-party/Luax/luax_enum.h
index c385dc5..395eaf0 100644
--- a/source/3rd-party/Luax/luax_enum.h
+++ b/source/3rd-party/Luax/luax_enum.h
@@ -19,7 +19,8 @@ namespace Luax
extern int l_rmt__newindex(lua_State* L);
- //--------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
+
#if LUAX_ENABLE_PLAIN_ENUM
///
/// luaö٣޸ĵtable
diff --git a/source/3rd-party/Luax/luax_reftable.cpp b/source/3rd-party/Luax/luax_reftable.cpp
index 602c9eb..461e2d9 100644
--- a/source/3rd-party/Luax/luax_reftable.cpp
+++ b/source/3rd-party/Luax/luax_reftable.cpp
@@ -72,7 +72,7 @@ namespace Luax
int LuaxRefTable::Ref(LuaxState& state, int idx)
{
- assert(mState && mState == state.GetHandle());
+ assert(mState);
idx = state.AbsIndex(idx);
state.GetField(LUA_REGISTRYINDEX, mName); // ref table
@@ -85,7 +85,7 @@ namespace Luax
void LuaxRefTable::Unref(LuaxState& state, int refID)
{
- assert(mState && mState == state.GetHandle());
+ assert(mState);
state.GetField(LUA_REGISTRYINDEX, mName); // ref table
luaL_unref(state, -1, refID);
@@ -95,14 +95,14 @@ namespace Luax
void LuaxRefTable::PushRefTable(LuaxState& state)
{
- assert(mState && mState == state.GetHandle());
+ assert(mState);
lua_getfield(state, LUA_REGISTRYINDEX, mName);
}
void LuaxRefTable::PushRef(LuaxState& state, int refID)
{
- assert(mState && mState == state.GetHandle());
+ assert(mState);
lua_getfield(state, LUA_REGISTRYINDEX, mName);
lua_rawgeti(state, -1, refID);
@@ -111,7 +111,7 @@ namespace Luax
void LuaxRefTable::Clear(LuaxState& state)
{
- assert(mState && mState == state.GetHandle());
+ assert(mState);
lua_newtable(state);
state.SetField(LUA_REGISTRYINDEX, mName);
diff --git a/source/3rd-party/Luax/luax_runtime.cpp b/source/3rd-party/Luax/luax_runtime.cpp
index b45d36a..dcf7b92 100644
--- a/source/3rd-party/Luax/luax_runtime.cpp
+++ b/source/3rd-party/Luax/luax_runtime.cpp
@@ -27,61 +27,69 @@ namespace Luax
assert(L);
// 1)
- mContexts.insert(pair<lua_State*, LuaxContext>(L, LuaxContext(L)));
+ mContexts.insert(pair<lua_State*, LuaxVM*>(L, new LuaxVM(L)));
// 2) ʼcontext
(*this)[L].Setup();
return L;
}
-
+/*
+ lua_State* LuaxRuntime::CreateThread(lua_State* main)
+ {
+ lua_State* thread = lua_newthread(main);
+ mContexts.insert(pair<lua_State*, LuaxVM*>(thread, mContexts[main]));
+ return thread;
+ }
+*/
void LuaxRuntime::Close(lua_State* L)
{
- map<lua_State*, LuaxContext>::iterator it = mContexts.find(L);
+ map<lua_State*, LuaxVM*>::iterator it = mContexts.find(L);
if (it != mContexts.end())
{
- lua_close(it->second.state);
+ lua_close(it->second->state);
mContexts.erase(it);
}
}
bool LuaxRuntime::HasLuaxState(lua_State* L)
{
- map<lua_State*, LuaxContext>::iterator it = mContexts.find(L);
+ map<lua_State*, LuaxVM*>::iterator it = mContexts.find(L);
return it != mContexts.end();
}
LuaxState& LuaxRuntime::GetLuaxState(lua_State* L)
{
- map<lua_State*, LuaxContext>::iterator it = mContexts.find(L);
+ map<lua_State*, LuaxVM*>::iterator it = mContexts.find(L);
if (it != mContexts.end())
{
- return it->second.state;
+ return it->second->state;
}
}
LuaxRefTable& LuaxRuntime::GetStrongRefTable(lua_State* L)
{
- map<lua_State*, LuaxContext>::iterator it = mContexts.find(L);
+ map<lua_State*, LuaxVM*>::iterator it = mContexts.find(L);
if (it != mContexts.end())
{
- return it->second.strongRefTable;
+ return it->second->strongRefTable;
}
}
LuaxRefTable& LuaxRuntime::GetWeaksRefTable(lua_State* L)
{
- map<lua_State*, LuaxContext>::iterator it = mContexts.find(L);
+ map<lua_State*, LuaxVM*>::iterator it = mContexts.find(L);
if (it != mContexts.end())
{
- return it->second.weakRefTable;
+ return it->second->weakRefTable;
}
}
- LuaxContext& LuaxRuntime::operator[](lua_State* L)
+ LuaxVM& LuaxRuntime::operator[](lua_State* L)
{
- map<lua_State*, LuaxContext>::iterator it = mContexts.find(L);
+ map<lua_State*, LuaxVM*>::iterator it = mContexts.find(L);
assert(it != mContexts.end());
- return it->second;
+
+ return *it->second;
}
}
diff --git a/source/3rd-party/Luax/luax_runtime.h b/source/3rd-party/Luax/luax_runtime.h
index 1234627..27c9af4 100644
--- a/source/3rd-party/Luax/luax_runtime.h
+++ b/source/3rd-party/Luax/luax_runtime.h
@@ -6,7 +6,7 @@
#include "luax_ref.h"
#include "luax_config.h"
#include "luax_state.h"
-#include "luax_context.h"
+#include "luax_vm.h"
namespace Luax
{
@@ -21,10 +21,15 @@ namespace Luax
static LuaxRuntime& Get();
///
- /// һµlua_Stateصlua_State*һ8\4ֽڵkey
+ /// һµluaʹ̲߳صlua_State*һ8\4ֽڵkey
///
lua_State* Open();
-
+/*
+ ///
+ /// ̴߳һ̡߳ӵcontextӳ䡣ҪΪ˷context߳ʡ
+ ///
+ lua_State* CreateThread(lua_State* mainThread);
+*/
///
/// رlua_Stateruntimeɾ
///
@@ -35,7 +40,7 @@ namespace Luax
LuaxRefTable& GetStrongRefTable(lua_State* L);
LuaxRefTable& GetWeaksRefTable(lua_State* L);
- LuaxContext& operator[](lua_State* L);
+ LuaxVM& operator[](lua_State* L);
private:
@@ -47,7 +52,7 @@ namespace Luax
///
/// lua_State handlecontextӳ
///
- std::map<lua_State*, LuaxContext> mContexts;
+ std::map<lua_State*, LuaxVM*> mContexts;
};
diff --git a/source/3rd-party/Luax/luax_state.cpp b/source/3rd-party/Luax/luax_state.cpp
index b7b89a3..f453be7 100644
--- a/source/3rd-party/Luax/luax_state.cpp
+++ b/source/3rd-party/Luax/luax_state.cpp
@@ -741,7 +741,7 @@ namespace Luax
}
template <>
- bool LuaxState::CheckParam < bool >(int idx)
+ bool LuaxState::CheckValue < bool >(int idx)
{
bool b = false;
if (lua_type(mState, idx) == LUA_TBOOLEAN)
@@ -756,73 +756,73 @@ namespace Luax
}
template <>
- cc8* LuaxState::CheckParam < cc8* >(int idx)
+ cc8* LuaxState::CheckValue < cc8* >(int idx)
{
return luaL_checkstring(mState, idx);
}
template <>
- double LuaxState::CheckParam < double >(int idx)
+ double LuaxState::CheckValue < double >(int idx)
{
return luaL_checknumber(mState, idx);
}
template <>
- float LuaxState::CheckParam < float >(int idx)
+ float LuaxState::CheckValue < float >(int idx)
{
return luaL_checknumber(mState, idx);
}
template <>
- s8 LuaxState::CheckParam < s8 >(int idx)
+ s8 LuaxState::CheckValue < s8 >(int idx)
{
return luaL_checkinteger(mState, idx);
}
template <>
- s16 LuaxState::CheckParam < s16 >(int idx)
+ s16 LuaxState::CheckValue < s16 >(int idx)
{
return luaL_checkinteger(mState, idx);
}
template <>
- s32 LuaxState::CheckParam < s32 >(int idx)
+ s32 LuaxState::CheckValue < s32 >(int idx)
{
return luaL_checkinteger(mState, idx);
}
template <>
- s64 LuaxState::CheckParam < s64 >(int idx)
+ s64 LuaxState::CheckValue < s64 >(int idx)
{
return luaL_checkinteger(mState, idx);
}
template <>
- u8 LuaxState::CheckParam < u8 >(int idx)
+ u8 LuaxState::CheckValue < u8 >(int idx)
{
return luaL_checkinteger(mState, idx);
}
template <>
- u16 LuaxState::CheckParam < u16 >(int idx)
+ u16 LuaxState::CheckValue < u16 >(int idx)
{
return luaL_checkinteger(mState, idx);
}
template <>
- u32 LuaxState::CheckParam < u32 >(int idx)
+ u32 LuaxState::CheckValue < u32 >(int idx)
{
return luaL_checkinteger(mState, idx);
}
template <>
- u64 LuaxState::CheckParam < u64 >(int idx)
+ u64 LuaxState::CheckValue < u64 >(int idx)
{
return luaL_checkinteger(mState, idx);
}
template <>
- std::string LuaxState::CheckParam < std::string >(int idx)
+ std::string LuaxState::CheckValue < std::string >(int idx)
{
return luaL_checkstring(mState, idx);
}
@@ -831,7 +831,7 @@ namespace Luax
/// check light userdata
///
template <>
- const void* LuaxState::CheckParam < const void* >(int idx)
+ const void* LuaxState::CheckValue < const void* >(int idx)
{
if (IsType(idx, LUA_TLIGHTUSERDATA))
{
diff --git a/source/3rd-party/Luax/luax_state.h b/source/3rd-party/Luax/luax_state.h
index e9c394a..b6d1ff0 100644
--- a/source/3rd-party/Luax/luax_state.h
+++ b/source/3rd-party/Luax/luax_state.h
@@ -9,7 +9,7 @@
namespace Luax
{
- class LuaxContext;
+ class LuaxVM;
class LuaxEnum;
class LuaxStrongRef;
class LuaxWeakRef;
@@ -20,7 +20,8 @@ namespace Luax
/// member table
/// ref table
/// userdata
- /// userdataͨgetmetatableȡϼmetatable֮⻹һclass tableעڶӦƿռ
+ /// userdataͨgetmetatableȡϼmetatable֮⻹һclass tableעڶӦ
+ /// ƿռ
///
LUAX_API class LuaxState
{
@@ -36,11 +37,11 @@ namespace Luax
///
inline lua_State* GetHandle() { return mState; };
- //------------------------------------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------//
void OpenLibs();
- //------------------------------------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------//
// ƿռƿռһ_Gı
void PushGlobalNamespace();
@@ -48,7 +49,7 @@ namespace Luax
void PopNamespace();
bool IsNamespace(int idx);
- //------------------------------------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------//
void SetTop(int top);
int GetTop();
@@ -56,7 +57,7 @@ namespace Luax
int AbsIndex(int idx);
void Call(int nArgs, int nResults);
- //------------------------------------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------//
void GetField(int idx, cc8* name);
void GetField(int idx, int key);
@@ -117,11 +118,11 @@ namespace Luax
template<typename T> T* GetUserdata(int idx = 1);
- //------------------------------------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------//
int ErrorType(int idx, cc8* hint);
- //------------------------------------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------//
template<typename T> T GetValue(int idx, T default_value);
template<typename T> T GetField(int idx, int key, T value);
@@ -130,14 +131,14 @@ namespace Luax
template<typename T> void SetFieldByIndex(int idx, int key, T value);
template<typename T> T* CheckUserdata(int idx);
- template<typename T> T CheckParam(int idx);
+ template<typename T> T CheckValue(int idx);
- //------------------------------------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------//
void DoString(const std::string& code);
void DoFile(const std::string& file);
- //------------------------------------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------//
// ע᷽
///
@@ -166,9 +167,9 @@ namespace Luax
void RegisterMethod(cc8* fname, lua_CFunction func);
///
- /// preloaderӵpackage.preloadrequire"libname"ʱlualoader_preloadlibnameҵpreloaderֱӼء
- /// ʵҪrequireʱżأҼعһκpackage.loaded¼´βټءͨrequire
- /// preloader
+ /// preloaderӵpackage.preloadrequire"libname"ʱlualoader_preload
+ /// libnameҵpreloaderֱӼءʵҪrequireʱżأҼعһκ
+ /// package.loaded¼´βټءͨrequirepreloader
///
void RegisterPreloader(cc8* libname, lua_CFunction preloader);
@@ -191,11 +192,11 @@ namespace Luax
void RegisterPlainEnumRegistry(cc8* name);
#endif
- //------------------------------------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------//
protected:
- friend class LuaxContext;
+ friend class LuaxVM;
LuaxState(lua_State* state);
LuaxState(const LuaxState& state);
@@ -211,7 +212,7 @@ namespace Luax
};
- //--------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
// GetValue()ģػ
template <> bool LuaxState::GetValue < bool >(int idx, const bool value);
@@ -229,23 +230,23 @@ namespace Luax
template <> std::string LuaxState::GetValue < std::string >(int idx, const std::string value);
template <> const void* LuaxState::GetValue < const void* >(int idx, const void* value);
- //--------------------------------------------------------------------------------------------------------------
- // CheckParamģػ
-
- template <> bool LuaxState::CheckParam < bool >(int idx);
- template <> cc8* LuaxState::CheckParam < cc8* >(int idx);
- template <> double LuaxState::CheckParam < double >(int idx);
- template <> float LuaxState::CheckParam < float >(int idx);
- template <> s8 LuaxState::CheckParam < s8 >(int idx);
- template <> s16 LuaxState::CheckParam < s16 >(int idx);
- template <> s32 LuaxState::CheckParam < s32 >(int idx);
- template <> s64 LuaxState::CheckParam < s64 >(int idx);
- template <> u8 LuaxState::CheckParam < u8 >(int idx);
- template <> u16 LuaxState::CheckParam < u16 >(int idx);
- template <> u32 LuaxState::CheckParam < u32 >(int idx);
- template <> u64 LuaxState::CheckParam < u64 >(int idx);
- template <> std::string LuaxState::CheckParam < std::string >(int idx);
- template <> const void* LuaxState::CheckParam < const void* >(int idx);
+ //--------------------------------------------------------------------------------//
+ // CheckValueģػ
+
+ template <> bool LuaxState::CheckValue < bool >(int idx);
+ template <> cc8* LuaxState::CheckValue < cc8* >(int idx);
+ template <> double LuaxState::CheckValue < double >(int idx);
+ template <> float LuaxState::CheckValue < float >(int idx);
+ template <> s8 LuaxState::CheckValue < s8 >(int idx);
+ template <> s16 LuaxState::CheckValue < s16 >(int idx);
+ template <> s32 LuaxState::CheckValue < s32 >(int idx);
+ template <> s64 LuaxState::CheckValue < s64 >(int idx);
+ template <> u8 LuaxState::CheckValue < u8 >(int idx);
+ template <> u16 LuaxState::CheckValue < u16 >(int idx);
+ template <> u32 LuaxState::CheckValue < u32 >(int idx);
+ template <> u64 LuaxState::CheckValue < u64 >(int idx);
+ template <> std::string LuaxState::CheckValue < std::string >(int idx);
+ template <> const void* LuaxState::CheckValue < const void* >(int idx);
///
/// ڳԱﴴLuaxStateԲм顣
@@ -258,7 +259,7 @@ namespace Luax
#define LUAX_STATE(L) \
Luax::LuaxState& state = Luax::LuaxRuntime::Get().GetLuaxState(L)
- //--------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
///
/// ȷȫluaܹڵ֮󷵻صstack״̬
diff --git a/source/3rd-party/Luax/luax_context.cpp b/source/3rd-party/Luax/luax_vm.cpp
index d41c24f..4257b4d 100644
--- a/source/3rd-party/Luax/luax_context.cpp
+++ b/source/3rd-party/Luax/luax_vm.cpp
@@ -1,25 +1,25 @@
-#include "luax_context.h"
+#include "luax_vm.h"
namespace Luax
{
- LuaxContext::LuaxContext(lua_State* L)
+ LuaxVM::LuaxVM(lua_State* L)
: state(L)
{
assert(state);
}
- LuaxContext::~LuaxContext()
+ LuaxVM::~LuaxVM()
{
}
// ʼcontext
- void LuaxContext::Setup()
+ void LuaxVM::Setup()
{
SetupRefTables();
}
- void LuaxContext::SetupRefTables()
+ void LuaxVM::SetupRefTables()
{
// strong ref weak ref
strongRefTable.Init(state, "_LUAX_STRONGREF_TABLE");
diff --git a/source/3rd-party/Luax/luax_context.h b/source/3rd-party/Luax/luax_vm.h
index 01c5937..e99d5b5 100644
--- a/source/3rd-party/Luax/luax_context.h
+++ b/source/3rd-party/Luax/luax_vm.h
@@ -11,15 +11,15 @@ namespace Luax
///
/// lua_stateصcontextһϵдļϣҲûϵҪΪ˽Լڴ档
///
- class LuaxContext
+ class LuaxVM
{
public:
- LuaxContext(lua_State* L);
- ~LuaxContext();
+ LuaxVM(lua_State* L);
+ ~LuaxVM();
void Setup();
- LuaxState state; // lua state
+ LuaxState state; // lua main state
LuaxRefTable strongRefTable; // strong ref table
LuaxRefTable weakRefTable; // weak ref table
@@ -29,6 +29,8 @@ namespace Luax
void SetupRefTables();
+ int mThreadsCount; // context߳
+
};
}
diff --git a/source/3rd-party/uuid4/uuid4.c b/source/3rd-party/uuid4/uuid4.c
new file mode 100644
index 0000000..1b60188
--- /dev/null
+++ b/source/3rd-party/uuid4/uuid4.c
@@ -0,0 +1,90 @@
+/**
+ * Copyright (c) 2018 rxi
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MIT license. See LICENSE for details.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+
+#if defined(_WIN32)
+#include <windows.h>
+#include <wincrypt.h>
+#endif
+
+#include "uuid4.h"
+
+
+static uint64_t seed[2];
+
+
+static uint64_t xorshift128plus(uint64_t *s) {
+ /* http://xorshift.di.unimi.it/xorshift128plus.c */
+ uint64_t s1 = s[0];
+ const uint64_t s0 = s[1];
+ s[0] = s0;
+ s1 ^= s1 << 23;
+ s[1] = s1 ^ s0 ^ (s1 >> 18) ^ (s0 >> 5);
+ return s[1] + s0;
+}
+
+
+int uuid4_init(void) {
+#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
+ int res;
+ FILE *fp = fopen("/dev/urandom", "rb");
+ if (!fp) {
+ return UUID4_EFAILURE;
+ }
+ res = fread(seed, 1, sizeof(seed), fp);
+ fclose(fp);
+ if ( res != sizeof(seed) ) {
+ return UUID4_EFAILURE;
+ }
+
+#elif defined(_WIN32)
+ int res;
+ HCRYPTPROV hCryptProv;
+ res = CryptAcquireContext(
+ &hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
+ if (!res) {
+ return UUID4_EFAILURE;
+ }
+ res = CryptGenRandom(hCryptProv, (DWORD) sizeof(seed), (PBYTE) seed);
+ CryptReleaseContext(hCryptProv, 0);
+ if (!res) {
+ return UUID4_EFAILURE;
+ }
+
+#else
+ #error "unsupported platform"
+#endif
+ return UUID4_ESUCCESS;
+}
+
+
+void uuid4_generate(char *dst) {
+ static const char *template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
+ static const char *chars = "0123456789abcdef";
+ union { unsigned char b[16]; uint64_t word[2]; } s;
+ const char *p;
+ int i, n;
+ /* get random */
+ s.word[0] = xorshift128plus(seed);
+ s.word[1] = xorshift128plus(seed);
+ /* build string */
+ p = template;
+ i = 0;
+ while (*p) {
+ n = s.b[i >> 1];
+ n = (i & 1) ? (n >> 4) : (n & 0xf);
+ switch (*p) {
+ case 'x' : *dst = chars[n]; i++; break;
+ case 'y' : *dst = chars[(n & 0x3) + 8]; i++; break;
+ default : *dst = *p;
+ }
+ dst++, p++;
+ }
+ *dst = '\0';
+}
diff --git a/source/3rd-party/uuid4/uuid4.h b/source/3rd-party/uuid4/uuid4.h
new file mode 100644
index 0000000..fb3ed2f
--- /dev/null
+++ b/source/3rd-party/uuid4/uuid4.h
@@ -0,0 +1,22 @@
+/**
+ * Copyright (c) 2018 rxi
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MIT license. See LICENSE for details.
+ */
+
+#ifndef UUID4_H
+#define UUID4_H
+
+#define UUID4_VERSION "1.0.0"
+#define UUID4_LEN 37
+
+enum {
+ UUID4_ESUCCESS = 0,
+ UUID4_EFAILURE = -1
+};
+
+int uuid4_init(void);
+void uuid4_generate(char *dst);
+
+#endif
diff --git a/source/Asura.Editor/widgets/binding/_button.cpp b/source/Asura.Editor/widgets/binding/_button.cpp
index 463aef6..fbae64f 100644
--- a/source/Asura.Editor/widgets/binding/_button.cpp
+++ b/source/Asura.Editor/widgets/binding/_button.cpp
@@ -37,7 +37,7 @@ namespace AsuraEditor
LUAX_STATE(L);
Button* self = state.GetUserdata<Button>(1);
- int msg = state.CheckParam<int>(2);
+ int msg = state.CheckValue<int>(2);
if (!lua_isfunction(L, 3))
return state.ErrorType(3, "callback");
diff --git a/source/Asura.Editor/widgets/button.h b/source/Asura.Editor/widgets/button.h
index 305cd35..14cd041 100644
--- a/source/Asura.Editor/widgets/button.h
+++ b/source/Asura.Editor/widgets/button.h
@@ -36,6 +36,8 @@ namespace AsuraEditor
{
public:
+ LUAX_DECL_FACTORY(Button);
+
Button();
~Button();
@@ -50,10 +52,10 @@ namespace AsuraEditor
int GetStatus();
void SetImage(int status, AEGraphics::Image* image);
- LUAX_DECL_FACTORY(Button);
-
private:
+ //------------------------------------------------------------------------------//
+
LUAX_DECL_ENUM(ButtonStatus);
LUAX_DECL_ENUM(ButtonMessage);
@@ -61,6 +63,8 @@ namespace AsuraEditor
LUAX_DECL_METHOD(_Disconnect);
LUAX_DECL_METHOD(_SetImage);
+ //------------------------------------------------------------------------------//
+
int mStatus; // ǰ״̬
Signal mSignals[_BUTTON_MSG_COUNT]; // 3Ϣsignal
AEGraphics::Image* mImage[_BUTTON_STATUS_COUNT]; // 5״̬ͼ
diff --git a/source/libs/asura-lib-core/graphics/binding/_image.cpp b/source/libs/asura-lib-core/graphics/binding/_image.cpp
index b455ad5..cb008d3 100644
--- a/source/libs/asura-lib-core/graphics/binding/_image.cpp
+++ b/source/libs/asura-lib-core/graphics/binding/_image.cpp
@@ -80,8 +80,8 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Image);
- uint x = state.CheckParam<uint>(2);
- uint y = state.CheckParam<uint>(3);
+ uint x = state.CheckValue<uint>(2);
+ uint y = state.CheckValue<uint>(3);
Color32* c32 = new Color32(self->GetPixel(x, y));
c32->PushLuaxUserdata(state);
return 1;
diff --git a/source/libs/asura-lib-core/graphics/image.h b/source/libs/asura-lib-core/graphics/image.h
index 4c1c7b5..4d9787b 100644
--- a/source/libs/asura-lib-core/graphics/image.h
+++ b/source/libs/asura-lib-core/graphics/image.h
@@ -22,8 +22,9 @@ namespace AsuraEngine
class ImageFactory;
///
- /// ImageͼƬڴ󣬶ȡϷ󱣴ĽһImageڴ桢ԴֻᱣһݣҪ
- /// imageêλãźתǶȣʹspriteһֻࡣҪǿǵeditorengineʹòͬķװ
+ /// ImageͼƬڴ󣬶ȡϷ󱣴ĽһImageڴ桢Դֻᱣһ
+ /// ݣҪimageêλãźתǶȣʹsprite
+ /// һֻࡣҪǿǵeditorengineʹòͬķװ
///
class Image ASURA_FINAL
: public Drawable
@@ -39,8 +40,8 @@ namespace AsuraEngine
~Image();
///
- /// bufferimageϢmPixelsΪգݡ¹imageʹglTexImage2Dύimage
- /// ݡ
+ /// bufferimageϢmPixelsΪգݡ¹image
+ /// ʹglTexImage2Dύimageݡ
///
bool Load(ImageData* data);
diff --git a/source/libs/asura-lib-core/graphics/shader.h b/source/libs/asura-lib-core/graphics/shader.h
index 575a37e..1c81355 100644
--- a/source/libs/asura-lib-core/graphics/shader.h
+++ b/source/libs/asura-lib-core/graphics/shader.h
@@ -94,7 +94,7 @@ namespace AsuraEngine
///
GLuint mProgramHandle;
- //------------------------------------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------//
public:
diff --git a/source/libs/asura-lib-core/input/mouse.h b/source/libs/asura-lib-core/input/mouse.h
index 0f34fdd..3ab67fa 100644
--- a/source/libs/asura-lib-core/input/mouse.h
+++ b/source/libs/asura-lib-core/input/mouse.h
@@ -1,8 +1,8 @@
#ifndef __ASURA_ENGINE_MOUSE_H__
#define __ASURA_ENGINE_MOUSE_H__
-#include "Cursor.h"
-#include "InputDevice.hpp"
+#include "cursor.h"
+#include "input_device.hpp"
namespace AsuraEngine
{
diff --git a/source/libs/asura-lib-core/graphics/window.cpp b/source/libs/asura-lib-core/window/window.cpp
index 83a4f53..83a4f53 100644
--- a/source/libs/asura-lib-core/graphics/window.cpp
+++ b/source/libs/asura-lib-core/window/window.cpp
diff --git a/source/libs/asura-lib-core/graphics/window.h b/source/libs/asura-lib-core/window/window.h
index 1b219a2..39db73e 100644
--- a/source/libs/asura-lib-core/graphics/window.h
+++ b/source/libs/asura-lib-core/window/window.h
@@ -4,8 +4,8 @@
#include <asura-lib-utils/scripting/portable.hpp>
#include <asura-lib-utils/math/vector2.hpp>
-#include "render_state.h"
-#include "render_target.h"
+#include "../graphics/render_state.h"
+#include "../graphics/render_target.h"
namespace AsuraEngine
{
diff --git a/source/libs/asura-lib-core/graphics/window_impl_glew.cpp b/source/libs/asura-lib-core/window/window_impl_glew.cpp
index e69de29..e69de29 100644
--- a/source/libs/asura-lib-core/graphics/window_impl_glew.cpp
+++ b/source/libs/asura-lib-core/window/window_impl_glew.cpp
diff --git a/source/libs/asura-lib-core/graphics/window_impl_glew.h b/source/libs/asura-lib-core/window/window_impl_glew.h
index e69de29..e69de29 100644
--- a/source/libs/asura-lib-core/graphics/window_impl_glew.h
+++ b/source/libs/asura-lib-core/window/window_impl_glew.h
diff --git a/source/libs/asura-lib-core/graphics/window_impl_glut.cpp b/source/libs/asura-lib-core/window/window_impl_glut.cpp
index e69de29..e69de29 100644
--- a/source/libs/asura-lib-core/graphics/window_impl_glut.cpp
+++ b/source/libs/asura-lib-core/window/window_impl_glut.cpp
diff --git a/source/libs/asura-lib-core/graphics/window_impl_glut.h b/source/libs/asura-lib-core/window/window_impl_glut.h
index e69de29..e69de29 100644
--- a/source/libs/asura-lib-core/graphics/window_impl_glut.h
+++ b/source/libs/asura-lib-core/window/window_impl_glut.h
diff --git a/source/libs/asura-lib-core/graphics/window_impl_sdl.cpp b/source/libs/asura-lib-core/window/window_impl_sdl.cpp
index e69de29..e69de29 100644
--- a/source/libs/asura-lib-core/graphics/window_impl_sdl.cpp
+++ b/source/libs/asura-lib-core/window/window_impl_sdl.cpp
diff --git a/source/libs/asura-lib-core/graphics/window_impl_sdl.h b/source/libs/asura-lib-core/window/window_impl_sdl.h
index e69de29..e69de29 100644
--- a/source/libs/asura-lib-core/graphics/window_impl_sdl.h
+++ b/source/libs/asura-lib-core/window/window_impl_sdl.h
diff --git a/source/libs/asura-lib-openal/sound.h b/source/libs/asura-lib-openal/sound.h
index 095bdb7..6c2d7c2 100644
--- a/source/libs/asura-lib-openal/sound.h
+++ b/source/libs/asura-lib-openal/sound.h
@@ -1,14 +1,18 @@
#ifndef __ASURA_ENGINE_SOUND_H__
#define __ASURA_ENGINE_SOUND_H__
-#include "Scripting/Portable.h"
+#include <asura-lib-utils/scripting/portable.hpp>
namespace AsuraEngine
{
namespace Audio
{
- class Sound ASURA_FINAL: virtual public Scripting::Portable
+ ///
+ /// Ƶļ
+ ///
+ class Sound ASURA_FINAL
+ : public AEScripting::Portable<Sound>
{
public:
diff --git a/source/libs/asura-lib-openal/sound_decode_task.cpp b/source/libs/asura-lib-openal/sound_decode_task.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-openal/sound_decode_task.cpp
diff --git a/source/libs/asura-lib-openal/sound_decode_task.h b/source/libs/asura-lib-openal/sound_decode_task.h
new file mode 100644
index 0000000..d39013f
--- /dev/null
+++ b/source/libs/asura-lib-openal/sound_decode_task.h
@@ -0,0 +1,25 @@
+#ifndef __ASURA_OPENAL_SOUND_DECODER_TASK_H__
+#define __ASURA_OPENAL_SOUND_DECODER_TASK_H__
+
+#include <asura-lib-utils/threading/thread_task.h>
+
+namespace AsuraEngine
+{
+ namespace OpenAL
+ {
+
+ ///
+ /// Ƶļ
+ ///
+ class SoundDecodeTask : public AEThreading::ThreadTask
+ {
+ public:
+
+ private:
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-openal/sound_decoder.cpp b/source/libs/asura-lib-openal/sound_decoder.cpp
new file mode 100644
index 0000000..ad9f761
--- /dev/null
+++ b/source/libs/asura-lib-openal/sound_decoder.cpp
@@ -0,0 +1,29 @@
+#ifndef __ASURA_ENGINE_SOUND_DECODER_H__
+#define __ASURA_ENGINE_SOUND_DECODER_H__
+
+#include "Sound.h"
+#include "FileSystem/DataBuffer.h"
+
+namespace AsuraEngine
+{
+ namespace Audio
+ {
+
+ ///
+ /// Ƶļ
+ ///
+ class SoundDecoder
+ {
+ public:
+
+ SoundDecoder();
+ virtual ~SoundDecoder();
+
+ virtual Sound* Decode(const Filesystem::DataBuffer* db);
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-openal/sound_decoder.h b/source/libs/asura-lib-openal/sound_decoder.h
index ad9f761..2a3f087 100644
--- a/source/libs/asura-lib-openal/sound_decoder.h
+++ b/source/libs/asura-lib-openal/sound_decoder.h
@@ -1,8 +1,9 @@
#ifndef __ASURA_ENGINE_SOUND_DECODER_H__
#define __ASURA_ENGINE_SOUND_DECODER_H__
-#include "Sound.h"
-#include "FileSystem/DataBuffer.h"
+#include <asura-lib-utils/io/data_buffer.h>
+
+#include "sound.h"
namespace AsuraEngine
{
@@ -19,7 +20,7 @@ namespace AsuraEngine
SoundDecoder();
virtual ~SoundDecoder();
- virtual Sound* Decode(const Filesystem::DataBuffer* db);
+ virtual Sound* Decode(const AEIO::DataBuffer* db);
};
diff --git a/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp
index c42888c..6725bc4 100644
--- a/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp
+++ b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp
@@ -10,12 +10,12 @@ namespace AsuraEngine
LUAX_REGISTRY(DataBuffer)
{
LUAX_REGISTER_METHODS(state,
- { "New", _New },
- { "GetBuffer", _GetData },
- { "GetSize", _GetSize },
- { "Refactor", _Refactor },
- { "Load", _Load },
- { "Clear", _Clear }
+ { "New", _New },
+ { "GetData", _GetData },
+ { "GetSize", _GetSize },
+ { "Refactor", _Refactor },
+ { "Load", _Load },
+ { "Clear", _Clear }
);
}
@@ -49,14 +49,14 @@ namespace AsuraEngine
}
}
- // lsting, len = databuffer:GetBuffer()
+ // lsting, len = databuffer:GetData()
LUAX_IMPL_METHOD(DataBuffer, _GetData)
{
LUAX_SETUP(L, "U");
DataBuffer* self = state.GetUserdata<DataBuffer>(1);
lua_pushlstring(L, self->GetData(), self->GetSize());
- return 2;
+ return 1;
}
// length = databuffer:GetSize()
@@ -74,7 +74,7 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, DataBuffer);
- size_t size = state.CheckParam<int>(2);
+ size_t size = state.CheckValue<int>(2);
self->Refactor(size);
return 0;
}
diff --git a/source/libs/asura-lib-utils/io/binding/_file.cpp b/source/libs/asura-lib-utils/io/binding/_file.cpp
index 0670379..c44bc90 100644
--- a/source/libs/asura-lib-utils/io/binding/_file.cpp
+++ b/source/libs/asura-lib-utils/io/binding/_file.cpp
@@ -49,7 +49,7 @@ namespace AsuraEngine
{
LUAX_STATE(L);
- cc8* name = state.CheckParam<cc8*>(1);
+ cc8* name = state.CheckValue<cc8*>(1);
File* file = new File(name);
file->PushLuaxUserdata(state);
return 1;
@@ -60,7 +60,7 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, File);
- File::FileMode mode = (File::FileMode)state.CheckParam<int>(2);
+ File::FileMode mode = (File::FileMode)state.CheckValue<int>(2);
state.Push(self->Open(mode));
return 1;
}
@@ -115,7 +115,7 @@ namespace AsuraEngine
DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
if (!db) return state.ErrorType(2, "DataBuffer");
- int len = state.CheckParam<int>(3);
+ int len = state.CheckValue<int>(3);
int size = self->Read(db, len);
state.Push(size);
return 1;
@@ -164,7 +164,7 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, File);
- int pos = state.CheckParam<int>(2);
+ int pos = state.CheckValue<int>(2);
state.Push(self->Seek(pos));
return 1;
}
@@ -174,8 +174,8 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, File);
- BufferMode mode = (BufferMode)state.CheckParam<int>(2);
- int size = state.CheckParam<int>(3);
+ BufferMode mode = (BufferMode)state.CheckValue<int>(2);
+ int size = state.CheckValue<int>(3);
state.Push(self->SetBuffer(mode, size));
return 1;
}
diff --git a/source/libs/asura-lib-utils/io/binding/_file_system.cpp b/source/libs/asura-lib-utils/io/binding/_file_system.cpp
index 7132456..3843451 100644
--- a/source/libs/asura-lib-utils/io/binding/_file_system.cpp
+++ b/source/libs/asura-lib-utils/io/binding/_file_system.cpp
@@ -46,7 +46,7 @@ namespace AsuraEngine
{
PREPARE(L);
- const char* arg0 = state.CheckParam<const char*>(1);
+ const char* arg0 = state.CheckValue<const char*>(1);
fs->Init(arg0);
return 0;
}
@@ -111,7 +111,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
std::string mp;
if (fs->GetMountPoint(path, ASURA_OUT mp))
state.Push(mp);
@@ -126,7 +126,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* dir = state.CheckParam<cc8*>(1);
+ cc8* dir = state.CheckValue<cc8*>(1);
fs->SetWriteDirectory(dir);
return 0;
}
@@ -146,7 +146,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* name = state.CheckParam<cc8*>(1);
+ cc8* name = state.CheckValue<cc8*>(1);
File* file = fs->NewFile(name);
if (file)
file->PushLuaxUserdata(state);
@@ -160,7 +160,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
state.Push(fs->NewDirectory(path));
return 1;
}
@@ -170,7 +170,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
state.Push(fs->Write(path, db));
return 1;
@@ -181,7 +181,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
state.Push(fs->Append(path, db));
return 1;
@@ -192,7 +192,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
state.Push(fs->Remove(path));
return 1;
}
@@ -202,7 +202,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
FileData* fd = fs->Read(path);
if (fd)
{
@@ -223,7 +223,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
FileInfo info;
if (fs->GetFileInfo(path, &info))
{
@@ -244,7 +244,7 @@ namespace AsuraEngine
{
PREPARE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
std::vector<std::string> items;
if(fs->GetDirectoryItems(path, ASURA_OUT items))
{
diff --git a/source/libs/asura-lib-utils/io/binding/_io_task.cpp b/source/libs/asura-lib-utils/io/binding/_io_task.cpp
index c03ff2a..b3c5988 100644
--- a/source/libs/asura-lib-utils/io/binding/_io_task.cpp
+++ b/source/libs/asura-lib-utils/io/binding/_io_task.cpp
@@ -16,19 +16,29 @@ namespace AsuraEngine
LUAX_POSTPROCESS(IOTask)
{
+ LUAX_REGISTER_ENUM(state, "EIOTaskType",
+ { "READ", IOTASK_TYPE_READ },
+ { "WRITE", IOTASK_TYPE_WRITE },
+ { "APPEND", IOTASK_TYPE_APPEND }
+ );
}
- // task = IOTask.New(path, dst)
+ // task = IOTask.New(path, buffer, type, callback)
LUAX_IMPL_METHOD(IOTask, _New)
{
LUAX_STATE(L);
- cc8* path = state.CheckParam<cc8*>(1);
+ cc8* path = state.CheckValue<cc8*>(1);
DataBuffer* db = state.CheckUserdata<DataBuffer>(2);
- IOTask* task = new IOTask(path, db);
+ IOTaskType type = (IOTaskType)state.CheckValue<int>(3);
+ bool cbk = state.GetTop() >= 4 && state.IsType(4, LUA_TFUNCTION);
+
+ IOTask* task = new IOTask(path, db, type);
+ task->SetLuaxMemberRef(state, task->mBufferRef, 2);
+ if(cbk)
+ task->SetLuaxMemberRef(state, task->mCallback, 4);
task->PushLuaxUserdata(state);
- task->SetLuaxMemberRef(state, task->mDstRef, 2);
return 1;
}
diff --git a/source/libs/asura-lib-utils/io/data_buffer.cpp b/source/libs/asura-lib-utils/io/data_buffer.cpp
index 000869d..5049b38 100644
--- a/source/libs/asura-lib-utils/io/data_buffer.cpp
+++ b/source/libs/asura-lib-utils/io/data_buffer.cpp
@@ -88,5 +88,15 @@ namespace AsuraEngine
return mSize;
}
+ void DataBuffer::Lock()
+ {
+ mMutex.Lock();
+ }
+
+ void DataBuffer::Unlock()
+ {
+ mMutex.Unlock();
+ }
+
}
} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/io/data_buffer.h b/source/libs/asura-lib-utils/io/data_buffer.h
index 9dfe541..445bdf4 100644
--- a/source/libs/asura-lib-utils/io/data_buffer.h
+++ b/source/libs/asura-lib-utils/io/data_buffer.h
@@ -34,6 +34,9 @@ namespace AsuraEngine
size_t Load(const void* bytes, std::size_t size);
void Move(void* bytes, std::size_t size);
void Clear();
+
+ void Lock();
+ void Unlock();
private:
diff --git a/source/libs/asura-lib-utils/io/file.cpp b/source/libs/asura-lib-utils/io/file.cpp
index 976203d..0ff8c90 100644
--- a/source/libs/asura-lib-utils/io/file.cpp
+++ b/source/libs/asura-lib-utils/io/file.cpp
@@ -134,7 +134,10 @@ namespace AsuraEngine
if (length < 0)
throw Exception("Invalid read size.");
- return PHYSFS_readBytes(mFileHandle, dst->GetData(), length);
+ dst->Lock();
+ size_t size = PHYSFS_readBytes(mFileHandle, dst->GetData(), length);
+ dst->Unlock();
+ return size;
}
size_t File::ReadAll(ASURA_OUT DataBuffer* dst)
@@ -149,7 +152,10 @@ namespace AsuraEngine
if (dst->GetSize() < length)
throw Exception("Data buffer is too small compares to file length.");
- return PHYSFS_readBytes(mFileHandle, dst->GetData(), length);
+ dst->Lock();
+ size_t size = PHYSFS_readBytes(mFileHandle, dst->GetData(), length);
+ dst->Unlock();
+ return size;
}
#ifdef ASURA_WINDOWS
diff --git a/source/libs/asura-lib-utils/io/io_task.cpp b/source/libs/asura-lib-utils/io/io_task.cpp
index 1a50e56..7203175 100644
--- a/source/libs/asura-lib-utils/io/io_task.cpp
+++ b/source/libs/asura-lib-utils/io/io_task.cpp
@@ -1,5 +1,8 @@
+#include "file_system.h"
#include "io_task.h"
+#include <iostream>
+
using namespace AEScripting;
using namespace Luax;
@@ -8,9 +11,9 @@ namespace AsuraEngine
namespace IO
{
- IOTask::IOTask(const std::string& path, DataBuffer* buffer)
+ IOTask::IOTask(const std::string& path, DataBuffer* buffer, IOTaskType type)
: mPath(path)
- , mDst(buffer)
+ , mBuffer(buffer)
{
}
@@ -20,17 +23,29 @@ namespace AsuraEngine
bool IOTask::Execute()
{
+ File file(mPath);
+ if (mType == IOTASK_TYPE_WRITE)
+ {
+
+ }
+ // pathȡݱmBuffer
+ else if (mType == IOTASK_TYPE_READ)
+ {
+ file.Open(File::FILE_MODE_READ);
+ file.ReadAll(mBuffer);
+ file.Close();
+ }
return true;
}
- void IOTask::Invoke(lua_State* thread)
+ void IOTask::Invoke()
{
if (mCallback)
{
- LuaxScopedState state(thread);
+ LuaxScopedState state(LuaEnv::Get()->GetMainState());
if (PushLuaxMemberRef(state, mCallback))
{
- PushLuaxMemberRef(state, mDstRef);
+ PushLuaxMemberRef(state, mBufferRef);
state.Call(1, 0);
}
}
diff --git a/source/libs/asura-lib-utils/io/io_task.h b/source/libs/asura-lib-utils/io/io_task.h
index a79b2a8..5f454ee 100644
--- a/source/libs/asura-lib-utils/io/io_task.h
+++ b/source/libs/asura-lib-utils/io/io_task.h
@@ -13,32 +13,42 @@ namespace AsuraEngine
namespace IO
{
+ enum IOTaskType
+ {
+ IOTASK_TYPE_READ,
+ IOTASK_TYPE_WRITE,
+ IOTASK_TYPE_APPEND,
+ };
+
///
/// ȡļ
///
class IOTask ASURA_FINAL
- : public AEScripting::Portable<IOTask>
- , public AEThreading::Task
+ : public AEThreading::Task
+ , public AEScripting::Portable<IOTask>
{
public:
LUAX_DECL_FACTORY(IOTask);
- IOTask(const std::string& path, DataBuffer* buffer);
+ IOTask(const std::string& path, DataBuffer* buffer, IOTaskType type);
~IOTask();
bool Execute() override ;
- void Invoke(lua_State* thread) override;
+ void Invoke() override;
private:
- std::string mPath;
-
- DataBuffer* mDst;
- Luax::LuaxMemberRef mDstRef;
+ LUAX_DECL_ENUM(IOTaskType);
LUAX_DECL_METHOD(_New);
+ std::string mPath;
+ IOTaskType mType;
+
+ ASURA_REF DataBuffer* mBuffer;
+ Luax::LuaxMemberRef mBufferRef;
+
};
}
diff --git a/source/libs/asura-lib-utils/scripting/lua_env.h b/source/libs/asura-lib-utils/scripting/lua_env.h
index a467479..3bef3df 100644
--- a/source/libs/asura-lib-utils/scripting/lua_env.h
+++ b/source/libs/asura-lib-utils/scripting/lua_env.h
@@ -16,21 +16,41 @@ namespace AsuraEngine
{
///
- /// ͨӿڷlua state
+ /// ͨӿڷlua stateAsura˼ǣ߳άһluaӦõҪ߼ڴlua
+ /// ߳߽ջ
///
class LuaEnv ASURA_FINAL : public Singleton<LuaEnv>
{
public:
- LuaEnv() : mMainState(0){};
+ LuaEnv() : mMainState(0) {};
~LuaEnv() {};
///
/// ִջ
///
- inline void Init(lua_State* L) { ASSERT(!mMainState); mMainState = L; };
+ inline void Init()
+ {
+ ASSERT(!mMainState);
+ // ߳
+ mMainState = Luax::LuaxRuntime::Get().Open();
+ ASSERT(mMainState);
+ };
- inline lua_State* GetMainState() { return mMainState; };
+ inline lua_State* GetMainState()
+ {
+ return mMainState;
+ };
+
+ inline Luax::LuaxState& GetMainLuaxState()
+ {
+ return Luax::LuaxRuntime::Get()[mMainState].state;
+ };
+
+ inline void Exit()
+ {
+ Luax::LuaxRuntime::Get().Close(mMainState);
+ }
private:
diff --git a/source/libs/asura-lib-utils/threading/binding/_thread.cpp b/source/libs/asura-lib-utils/threading/binding/_thread.cpp
index 00252a9..9403486 100644
--- a/source/libs/asura-lib-utils/threading/binding/_thread.cpp
+++ b/source/libs/asura-lib-utils/threading/binding/_thread.cpp
@@ -18,7 +18,8 @@ namespace AsuraEngine
{ "AddTask", _AddTask },
{ "IsRunning", _IsRunning },
{ "IsCurrent", _IsCurrent },
- { "GetName", _GetName }
+ { "GetName", _GetName },
+ { "Sleep", _Sleep }
);
}
@@ -81,7 +82,7 @@ namespace AsuraEngine
LUAX_PREPARE(L, Thread);
state.Push(self->IsRunning());
- return 0;
+ return 1;
}
// thread:IsCurrent()
@@ -90,7 +91,7 @@ namespace AsuraEngine
LUAX_PREPARE(L, Thread);
state.Push(self->IsCurrent());
- return 0;
+ return 1;
}
// thread:GetName()
@@ -98,6 +99,20 @@ namespace AsuraEngine
{
LUAX_PREPARE(L, Thread);
+ state.Push(self->GetName());
+ return 1;
+ }
+
+ // Thread.Sleep(milliseconds)
+ LUAX_IMPL_METHOD(Thread, _Sleep)
+ {
+ LUAX_STATE(L);
+ int ms = state.CheckValue<int>(1);
+#if ASURA_THREAD_WIN32
+ ::Sleep(ms);
+#elif ASURA_THREAD_STD
+
+#endif
return 0;
}
diff --git a/source/libs/asura-lib-utils/threading/mutex.h b/source/libs/asura-lib-utils/threading/mutex.h
index 51fe63e..7e7d877 100644
--- a/source/libs/asura-lib-utils/threading/mutex.h
+++ b/source/libs/asura-lib-utils/threading/mutex.h
@@ -32,15 +32,15 @@ namespace AsuraEngine
};
- class Lock
+ class _mutex_locker
{
public:
- Lock(Mutex& mutex)
+ _mutex_locker(Mutex& mutex)
: m(mutex)
{
m.Lock();
};
- ~Lock()
+ ~_mutex_locker()
{
m.Unlock();
}
@@ -50,11 +50,11 @@ namespace AsuraEngine
};
// ڵջӴλÿʼջΪٽ
-#define lock(mutex) Lock _asura_scoped_lock_0x0_(mutex)
-#define lock2(mutex) Lock _asura_scoped_lock_0x1_(mutex)
-#define lock3(mutex) Lock _asura_scoped_lock_0x2_(mutex)
-#define lock4(mutex) Lock _asura_scoped_lock_0x3_(mutex)
-#define lock5(mutex) Lock _asura_scoped_lock_0x4_(mutex)
+#define lock(mutex) _mutex_locker _asura_scoped_lock_0x0(mutex)
+#define lock2(mutex) _mutex_locker _asura_scoped_lock_0x1(mutex)
+#define lock3(mutex) _mutex_locker _asura_scoped_lock_0x2(mutex)
+#define lock4(mutex) _mutex_locker _asura_scoped_lock_0x3(mutex)
+#define lock5(mutex) _mutex_locker _asura_scoped_lock_0x4(mutex)
ASURA_ABSTRACT class MutexImpl
{
diff --git a/source/libs/asura-lib-utils/threading/task.cpp b/source/libs/asura-lib-utils/threading/task.cpp
index e69de29..2e84ed4 100644
--- a/source/libs/asura-lib-utils/threading/task.cpp
+++ b/source/libs/asura-lib-utils/threading/task.cpp
@@ -0,0 +1,12 @@
+#include "task.h"
+#include "../scripting/lua_env.h"
+
+using namespace AEScripting;
+
+namespace AsuraEngine
+{
+ namespace Threading
+ {
+
+ }
+}
diff --git a/source/libs/asura-lib-utils/threading/task.h b/source/libs/asura-lib-utils/threading/task.h
index 9f78860..9c0b12c 100644
--- a/source/libs/asura-lib-utils/threading/task.h
+++ b/source/libs/asura-lib-utils/threading/task.h
@@ -13,12 +13,12 @@ namespace AsuraEngine
/// ϣһ̴߳񣬼̳TaskдExecute
///
ASURA_ABSTRACT class Task
- : virtual public AEScripting::NativeAccessor
+ : public virtual AEScripting::NativeAccessor
{
public:
- Task();
- virtual ~Task();
+ Task() {};
+ virtual ~Task() {};
///
/// ִɺ󷵻trueûص
@@ -28,10 +28,11 @@ namespace AsuraEngine
///
/// ûص
///
- virtual void Invoke(lua_State* thread) = 0;
+ virtual void Invoke() = 0;
- protected:
+ protected:
+ // ȡص
Luax::LuaxMemberRef mCallback;
};
diff --git a/source/libs/asura-lib-utils/threading/thread.cpp b/source/libs/asura-lib-utils/threading/thread.cpp
index 51738de..9c71ace 100644
--- a/source/libs/asura-lib-utils/threading/thread.cpp
+++ b/source/libs/asura-lib-utils/threading/thread.cpp
@@ -13,9 +13,6 @@ namespace AsuraEngine
Thread::Thread(Luax::LuaxState& father, const std::string& name)
: mName(name)
{
- mState = lua_newthread(father);
- SetLuaxMemberRef(father, mStateRef, -1);
- lua_pop(father, 1); // mState
}
Thread::~Thread()
@@ -79,13 +76,18 @@ namespace AsuraEngine
return mName;
}
- void Thread::Execute()
+ void Thread::Process()
{
+ LUAX_STATE(AEScripting::LuaEnv::Get()->GetMainState());
while (!mTaskQueue.empty())
{
Task* task = mTaskQueue.front();
- if (task->Execute())
- task->Invoke(mState);
+ if (task && task->Execute())
+ {
+ // unsafe
+ task->Invoke();
+ this->LuaxRelease<Task>(state, task);
+ }
mMutex.Lock();
mTaskQueue.pop();
diff --git a/source/libs/asura-lib-utils/threading/thread.h b/source/libs/asura-lib-utils/threading/thread.h
index 1bd5f15..3fa079a 100644
--- a/source/libs/asura-lib-utils/threading/thread.h
+++ b/source/libs/asura-lib-utils/threading/thread.h
@@ -17,6 +17,28 @@ namespace AsuraEngine
class ThreadImpl;
///
+ /// ̵߳ļֲͬʵ֣
+ /// 1: Deferredӳģʽ߳ϵɺҪ̵ֶ߳Post
+ /// ̵߳ص첽Ϊͬlua_Stateͻ⡣
+ /// 2: Immediateģʽÿһ߳άһlua_newthreadlua_State
+ /// صڲͬlua_Stateеãⲻ̷ͬ߳ͬһlua_State
+ /// 3: Daemonػģʽ̻߳һֱں̨
+ ///
+ enum ThreadType
+ {
+ THREAD_TYPE_DEFERRED,
+ THREAD_TYPE_IMMEDIATE,
+ THREAD_TYPE_DAEMON
+ };
+
+ enum ThreadState
+ {
+ THREAD_STATE_RUNNING,
+ THREAD_STATE_DEAD,
+ THREAD_STATE_SUSPEND,
+ };
+
+ ///
/// ߳壬ÿ߳άһtask queue
///
class Thread ASURA_FINAL
@@ -26,7 +48,7 @@ namespace AsuraEngine
LUAX_DECL_FACTORY(Thread);
- Thread(Luax::LuaxState& father, const std::string& name = "");
+ Thread(ThreadType type, Luax::LuaxState& luaThread, const std::string& name = "");
~Thread();
bool AddTask(Task* task);
@@ -34,8 +56,10 @@ namespace AsuraEngine
void Start(uint32 stacksize = 0);
///
- /// ǿֹ̡߳עҪnewdeleteִ֮TerminateThread򽫲ڼʹnewˡ
+ /// ǿֹ̡߳עҪnewdeleteִ֮TerminateThread򽫲ڼ
+ /// ʹnewˡ
/// https://blog.csdn.net/anye3000/article/details/7470674
+ /// ע⣺ҪʹӿڣӦ߳Լеյ㣬ֶر
///
void Kill();
@@ -51,12 +75,21 @@ namespace AsuraEngine
///
/// ִС
///
- void Execute();
+ void Process();
const std::string& GetName();
+ ///
+ /// ص
+ ///
+ void Post();
+
private:
+ //----------------------------------------------------------------------------//
+
+ LUAX_DECL_ENUM(ThreadType);
+
LUAX_DECL_METHOD(_New);
LUAX_DECL_METHOD(_Start);
LUAX_DECL_METHOD(_Join);
@@ -65,6 +98,10 @@ namespace AsuraEngine
LUAX_DECL_METHOD(_IsRunning);
LUAX_DECL_METHOD(_IsCurrent);
LUAX_DECL_METHOD(_GetName);
+ LUAX_DECL_METHOD(_Sleep);
+ LUAX_DECL_METHOD(_Post);
+
+ //----------------------------------------------------------------------------//
ThreadImpl* mImpl;
std::string mName;
@@ -75,11 +112,10 @@ namespace AsuraEngine
std::queue<Task*> mTaskQueue;
Mutex mMutex;
- ///
- /// ̵߳luaִջΪ˱ִջͻ
- ///
- lua_State* mState;
- Luax::LuaxMemberRef mStateRef;
+ lua_State* mLuaThread;
+
+ std::queue<Task*> mFinishedTasks;
+ Mutex mFinishedMutex;
};
diff --git a/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp b/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp
index e69de29..d2ad7af 100644
--- a/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp
+++ b/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp
@@ -0,0 +1,9 @@
+#include "thread_impl_posix.h"
+
+namespace AsuraEngine
+{
+ namespace Threading
+ {
+
+ }
+} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp b/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp
index fd1b066..ad859b6 100644
--- a/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp
+++ b/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp
@@ -1,6 +1,8 @@
#include "thread_impl_win32.h"
#include "thread.h"
+#include <iostream>
+
namespace AsuraEngine
{
namespace Threading
@@ -9,7 +11,11 @@ namespace AsuraEngine
static DWORD WINAPI _thread_win32_runner(LPVOID param)
{
Thread* thread = (Thread*)param;
- thread->Execute();
+ while (thread->IsRunning())
+ {
+ thread->Process();
+ ::Sleep(100);
+ }
return 0;
}
diff --git a/source/libs/asura-lib-utils/threading/thread_task.cpp b/source/libs/asura-lib-utils/threading/thread_task.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_task.cpp
diff --git a/source/libs/asura-lib-utils/threading/thread_task.h b/source/libs/asura-lib-utils/threading/thread_task.h
new file mode 100644
index 0000000..1ea0a1a
--- /dev/null
+++ b/source/libs/asura-lib-utils/threading/thread_task.h
@@ -0,0 +1,44 @@
+#ifndef __ASURA_THRAD_TASK_H__
+#define __ASURA_THRAD_TASK_H__
+
+#include <asura-lib-utils/type.h>
+#include <asura-lib-utils/scripting/portable.hpp>
+
+namespace AsuraEngine
+{
+ namespace Threading
+ {
+
+ ///
+ /// ϣһ̴߳񣬼̳TaskдExecute
+ ///
+ ASURA_ABSTRACT class ThreadTask
+ : virtual public AEScripting::NativeAccessor
+ {
+ public:
+
+ ThreadTask();
+ virtual ~ThreadTask();
+
+ ///
+ /// ִɺ󷵻trueûص
+ ///
+ virtual bool Execute() = 0;
+
+ ///
+ /// ûص
+ ///
+ virtual void Invoke() = 0;
+
+ protected:
+
+ Luax::LuaxMemberRef mCallback;
+
+ };
+
+ }
+}
+
+namespace AEThreading = AsuraEngine::Threading;
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/type.h b/source/libs/asura-lib-utils/type.h
index aa00108..1ed2d42 100644
--- a/source/libs/asura-lib-utils/type.h
+++ b/source/libs/asura-lib-utils/type.h
@@ -7,7 +7,7 @@
namespace AsuraEngine
{
- //----------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
typedef int8_t int8;
typedef uint8_t uint8;
@@ -27,7 +27,7 @@ namespace AsuraEngine
typedef const char cc8;
- //----------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
#ifndef ASSERT
#ifdef NDEBUG
@@ -42,7 +42,7 @@ namespace AsuraEngine
#endif
#endif
- //----------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
#ifdef _WIN32
#define ASURA_FINAL final
@@ -76,7 +76,7 @@ namespace AsuraEngine
///
#define ASURA_MOVE
- //----------------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------//
#define ASURA_SDL_HOST 1
diff --git a/source/libs/asura-lib-utils/utils_module.cpp b/source/libs/asura-lib-utils/utils_module.cpp
index a0539ed..61780e6 100644
--- a/source/libs/asura-lib-utils/utils_module.cpp
+++ b/source/libs/asura-lib-utils/utils_module.cpp
@@ -13,6 +13,7 @@ namespace AsuraEngine
LUAX_REGISTER_FACTORY(state, DataBuffer);
LUAX_REGISTER_FACTORY(state, FileData);
LUAX_REGISTER_FACTORY(state, File);
+ LUAX_REGISTER_FACTORY(state, IOTask);
// Threading
LUAX_REGISTER_FACTORY(state, Thread);
}
diff --git a/source/libs/asura-lib-utils/utils_module.h b/source/libs/asura-lib-utils/utils_module.h
index ae875b9..e802730 100644
--- a/source/libs/asura-lib-utils/utils_module.h
+++ b/source/libs/asura-lib-utils/utils_module.h
@@ -5,6 +5,7 @@
#include "io/data_buffer.h"
#include "io/file_data.h"
#include "io/file.h"
+#include "io/io_task.h"
#include "threading/thread.h"
diff --git a/source/tests/02-luax/main.cpp b/source/tests/02-luax/main.cpp
index d5fe3bf..59a4bcb 100644
--- a/source/tests/02-luax/main.cpp
+++ b/source/tests/02-luax/main.cpp
@@ -15,7 +15,7 @@ extern "C"{
using namespace std;
using namespace Luax;
-//----------------------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------//
class School
: public Singleton<School>
@@ -64,7 +64,7 @@ void School::RegisterLuaxPostprocess(Luax::LuaxState&)
{
}
-//----------------------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------//
class Boy : public LuaxNativeClass<Boy>
{
@@ -186,7 +186,7 @@ void Boy::RegisterLuaxPostprocess(LuaxState& state)
);
}
-//----------------------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------//
///
/// Ӧsignalıհ
///
@@ -253,11 +253,11 @@ private:
};
-//----------------------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------//
#include "script.lua"
-//----------------------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------//
int func(lua_State* L)
{
diff --git a/source/tests/05-physfs/main.cpp b/source/tests/05-physfs/main.cpp
index 28e55e9..14a2745 100644
--- a/source/tests/05-physfs/main.cpp
+++ b/source/tests/05-physfs/main.cpp
@@ -2,10 +2,12 @@
#include <asura-lib-utils/utils.h>
-using namespace Luax;
using namespace std;
+using namespace AEScripting;
string code = R"(
+local thread = nil
+local dst = nil
function main()
local suc = Filesystem.Init(arg0)
print(suc)
@@ -24,6 +26,28 @@ function main()
print(file:GetExtension())
print(file:GetName())
+ dst = DataBuffer.New(138567)
+ thread = Thread.New("IO thread")
+ local content = ""
+ local cont = "ok"
+ local task = IOTask.New("root/physfs2.txt", dst, EIOTaskType.READ, function(db)
+ function _r()
+ print("test..............")
+ local c = db:GetData()
+ print(c)
+ end
+ function err(msg)
+ print(msg)
+ end
+ xpcall(_r, err)
+ end)
+ thread:AddTask(task)
+ thread:Start()
+
+ print("-------------end-------------")
+
+ print(thread:GetName())
+
io.read()
end
@@ -38,18 +62,21 @@ int main(int argc, char* args[])
{
AsuraEngine::UtilsModule utils;
- lua_State* L = LuaxRuntime::Get().Open();
- AEScripting::LuaEnv::Get()->Init(L);
- LuaxState& state = LuaxRuntime::Get().GetLuaxState(L);
+ // ÿһasura򱣴һlua stateһһlua߳
+ AEScripting::LuaEnv::Get()->Init();
+
+ Luax::LuaxState& state = LuaEnv::Get()->GetMainLuaxState();
+
state.OpenLibs();
state.PushGlobalNamespace();
if(argc > 0)
state.SetField(-1, "arg0", args[0]);
utils.Initialize(state);
state.PopNamespace();
+
state.DoString(code);
- LuaxRuntime::Get().Close(L);
+ LuaEnv::Get()->Exit();
return 0;
} \ No newline at end of file