commit b2635c074aa36e86491d0b1fceeacfc2ba2ee7e4 Author: ouczbs Date: Wed Jul 5 09:24:50 2023 +0800 upload xmake project diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1f2eb5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.vs/ +.vscode/.cache/ +.vscode/compile_commands.json +.xmake/ +build/ +vsxmake*/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c98244c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,67 @@ +{ + "deploy.reloaded": { + "ignoreSettingsFolder": false, + "ignore": [ + "bin/**", + ".vs/**", + ".ipynb_checkpoints/**" + ], + "packages": [ + { + "name": "clua", + "description": "C + Lua API", + "files": [ + ".vscode/**", + "**/*.json", + "**/*.cpp", + "**/*.h", + "**/*.lua", + "**/*.proto" + ], + "deployOnSave": [ + "sync" + ] + }, + { + "name": "vscode", + "description": "vscode", + "files": [ + ".vscode/**" + ], + "exclude": [ + "x64/**", + ".vs/**" + ], + "deployOnSave": [ + "vscode" + ] + } + ], + "targets": [ + { + "type": "sftp", + "name": "sync", + "description": "my tercent server for sync", + "dir": "/data/jupyter/sync/zlua", + "host": "124.221.147.27", + "port": 22, + "user": "root", + "password": "@qq18770302583", + "checkBeforeDeploy": true, + "mappings": { + ".vscode/**/*": "_vscode/" + } + }, + { + "type": "local", + "name": "vscode", + "dir": "_vscode", + "checkBeforeDeploy": true, + "exclude": [ + "**/*.json" + ] + } + ] + }, + "xmake.executable": "xmake" +} \ No newline at end of file diff --git a/.vscode/sftp.json b/.vscode/sftp.json new file mode 100644 index 0000000..563d355 --- /dev/null +++ b/.vscode/sftp.json @@ -0,0 +1,22 @@ +{ + "name": "sync", + "host": "124.221.147.27", + "protocol": "sftp", + "port": 22, + "username": "root", + "password": "@qq18770302583", + "remotePath": "/data/jupyter/sync/zlua", + "uploadOnSave": false, + "useTempFile": false, + "openSsh": false, + "ignore": [ + ".xmake", + ".vs", + ".git", + "build", + "*.pb", + "*.pb.cc", + "*.pb.h", + ".ipynb_checkpoints/**" + ] +} \ No newline at end of file diff --git a/src/clua/xmake.lua b/src/clua/xmake.lua new file mode 100644 index 0000000..9700b80 --- /dev/null +++ b/src/clua/xmake.lua @@ -0,0 +1,46 @@ + + + +target("clua") + set_kind("binary") + add_includedirs("src", {public = true}) + add_packages("lua","luasocket") + add_packages("protobuf-cpp","lua-protobuf") + + add_files("src/*.cpp","src/**/*.cpp") + + add_rules("protobuf.cpp") + add_files("proto/**.proto", {proto_rootdir = "src"}) + + add_headerfiles("src/*.h","src/**/*.h") + + -- add_files("proto/*.proto", {rule = "protobuf.cpp", proto_rootdir = "proto"}) + -- add_files("proto/cpp/*.cc") + -- add_headerfiles("proto/cpp/*.h") + before_build(function (target) + os.cd("$(scriptdir)/proto") + os.execv("pb2pbc.bat") + os.exec("pb2cpp.bat") + target:add("files","cpp/*.cc") + target:add("headerfiles","cpp/*.h") + end ) + -- before_package(function(package) + -- print("before_package") + -- end) + -- before_install(function(package) + -- print("before_install") + -- end) + -- before_run(function(package) + -- print("before_run") + -- end) +-- add_rules("mode.debug", "mode.release") +-- add_requires("protobuf-cpp") + +-- target("test") +-- set_kind("binary") +-- set_languages("c++11") +-- add_packages("protobuf-cpp") +-- add_rules("protobuf.cpp") +-- add_files("src/*.cpp") +-- add_files("src/**.proto", {proto_rootdir = "src"}) + diff --git a/src/xmake.lua b/src/xmake.lua new file mode 100644 index 0000000..ff7f85a --- /dev/null +++ b/src/xmake.lua @@ -0,0 +1,4 @@ + +add_requires("lua","luasocket") +add_requires("protobuf-cpp","lua-protobuf") +includes("*/xmake.lua") \ No newline at end of file diff --git a/src/zcore/src/log/log_system.cpp b/src/zcore/src/log/log_system.cpp new file mode 100644 index 0000000..b1b39b6 --- /dev/null +++ b/src/zcore/src/log/log_system.cpp @@ -0,0 +1,30 @@ +#include "log_system.h" +#include +#include +#include +#include +LogSystem::LogSystem() +{ + auto console_sink = std::make_shared(); + console_sink->set_level(spdlog::level::trace); + console_sink->set_pattern("[%Y-%m-%d %H:%M:%S] %l %^%v%$"); + + const spdlog::sinks_init_list sink_list = {console_sink}; + + spdlog::init_thread_pool(8192, 1); + + m_logger = std::make_shared("muggle_logger", + sink_list.begin(), + sink_list.end(), + spdlog::thread_pool(), + spdlog::async_overflow_policy::block); + m_logger->set_level(spdlog::level::trace); + + spdlog::register_logger(m_logger); +} + +LogSystem::~LogSystem() +{ + m_logger->flush(); + spdlog::drop_all(); +} \ No newline at end of file diff --git a/src/zcore/src/log/log_system.h b/src/zcore/src/log/log_system.h new file mode 100644 index 0000000..5ef3d64 --- /dev/null +++ b/src/zcore/src/log/log_system.h @@ -0,0 +1,59 @@ +#pragma once + +#include "spdlog/spdlog.h" + +#include +#include + +class LogSystem final +{ +public: + enum class LogLevel : uint8_t + { + debug, + info, + warn, + error, + fatal + }; + +public: + LogSystem(); + ~LogSystem(); + + template + void log(LogLevel level, TARGS&&... args) + { + switch (level) + { + case LogLevel::debug: + m_logger->debug(std::forward(args)...); + break; + case LogLevel::info: + m_logger->info(std::forward(args)...); + break; + case LogLevel::warn: + m_logger->warn(std::forward(args)...); + break; + case LogLevel::error: + m_logger->error(std::forward(args)...); + break; + case LogLevel::fatal: + m_logger->critical(std::forward(args)...); + fatalCallback(std::forward(args)...); + break; + default: + break; + } + } + + template + void fatalCallback(TARGS&&... args) + { + const std::string format_str = fmt::format(std::forward(args)...); + throw std::runtime_error(format_str); + } + +private: + std::shared_ptr m_logger; +}; \ No newline at end of file diff --git a/src/zcore/xmake.lua b/src/zcore/xmake.lua new file mode 100644 index 0000000..6a39c24 --- /dev/null +++ b/src/zcore/xmake.lua @@ -0,0 +1,77 @@ + +target("zcore") + set_kind("static") + add_packages("spdlog", {public = true}) + add_includedirs("src", {public = true}) + add_files("src/**/*.cpp") + add_headerfiles("src/**/*.h") + +-- +-- If you want to known more usage about xmake, please see https://xmake.io +-- +-- ## FAQ +-- +-- You can enter the project directory firstly before building project. +-- +-- $ cd projectdir +-- +-- 1. How to build project? +-- +-- $ xmake +-- +-- 2. How to configure project? +-- +-- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] +-- +-- 3. Where is the build output directory? +-- +-- The default output directory is `./build` and you can configure the output directory. +-- +-- $ xmake f -o outputdir +-- $ xmake +-- +-- 4. How to run and debug target after building project? +-- +-- $ xmake run [targetname] +-- $ xmake run -d [targetname] +-- +-- 5. How to install target to the system directory or other output directory? +-- +-- $ xmake install +-- $ xmake install -o installdir +-- +-- 6. Add some frequently-used compilation flags in xmake.lua +-- +-- @code +-- -- add debug and release modes +-- add_rules("mode.debug", "mode.release") +-- +-- -- add macro definition +-- add_defines("NDEBUG", "_GNU_SOURCE=1") +-- +-- -- set warning all as error +-- set_warnings("all", "error") +-- +-- -- set language: c99, c++11 +-- set_languages("c99", "c++11") +-- +-- -- set optimization: none, faster, fastest, smallest +-- set_optimize("fastest") +-- +-- -- add include search directories +-- add_includedirs("/usr/include", "/usr/local/include") +-- +-- -- add link libraries and search directories +-- add_links("tbox") +-- add_linkdirs("/usr/local/lib", "/usr/lib") +-- +-- -- add system link libraries +-- add_syslinks("z", "pthread") +-- +-- -- add compilation and link flags +-- add_cxflags("-stdnolib", "-fno-strict-aliasing") +-- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) +-- +-- @endcode +-- + diff --git a/src/zfile/xmake.lua b/src/zfile/xmake.lua new file mode 100644 index 0000000..0c7c665 --- /dev/null +++ b/src/zfile/xmake.lua @@ -0,0 +1,76 @@ +add_rules("mode.debug", "mode.release") + +target("zfile") + set_kind("binary") + add_files("src/*.cpp") + add_headerfiles("src/*.h") + +-- +-- If you want to known more usage about xmake, please see https://xmake.io +-- +-- ## FAQ +-- +-- You can enter the project directory firstly before building project. +-- +-- $ cd projectdir +-- +-- 1. How to build project? +-- +-- $ xmake +-- +-- 2. How to configure project? +-- +-- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] +-- +-- 3. Where is the build output directory? +-- +-- The default output directory is `./build` and you can configure the output directory. +-- +-- $ xmake f -o outputdir +-- $ xmake +-- +-- 4. How to run and debug target after building project? +-- +-- $ xmake run [targetname] +-- $ xmake run -d [targetname] +-- +-- 5. How to install target to the system directory or other output directory? +-- +-- $ xmake install +-- $ xmake install -o installdir +-- +-- 6. Add some frequently-used compilation flags in xmake.lua +-- +-- @code +-- -- add debug and release modes +-- add_rules("mode.debug", "mode.release") +-- +-- -- add macro definition +-- add_defines("NDEBUG", "_GNU_SOURCE=1") +-- +-- -- set warning all as error +-- set_warnings("all", "error") +-- +-- -- set language: c99, c++11 +-- set_languages("c99", "c++11") +-- +-- -- set optimization: none, faster, fastest, smallest +-- set_optimize("fastest") +-- +-- -- add include search directories +-- add_includedirs("/usr/include", "/usr/local/include") +-- +-- -- add link libraries and search directories +-- add_links("tbox") +-- add_linkdirs("/usr/local/lib", "/usr/lib") +-- +-- -- add system link libraries +-- add_syslinks("z", "pthread") +-- +-- -- add compilation and link flags +-- add_cxflags("-stdnolib", "-fno-strict-aliasing") +-- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) +-- +-- @endcode +-- + diff --git a/src/zlua/config/BPConfig.ini b/src/zlua/config/BPConfig.ini new file mode 100644 index 0000000..862bcee --- /dev/null +++ b/src/zlua/config/BPConfig.ini @@ -0,0 +1,5 @@ + + +BP_MMOGameMode MMOGameMode +0 +UI_FunBtnEntryGameWorld.UI.Entry.FunBtnEntry \ No newline at end of file diff --git a/src/zlua/config/BPConfig.txt b/src/zlua/config/BPConfig.txt new file mode 100644 index 0000000..862bcee --- /dev/null +++ b/src/zlua/config/BPConfig.txt @@ -0,0 +1,5 @@ + + +BP_MMOGameMode MMOGameMode +0 +UI_FunBtnEntryGameWorld.UI.Entry.FunBtnEntry \ No newline at end of file diff --git a/src/zlua/lua/config.lua b/src/zlua/lua/config.lua new file mode 100644 index 0000000..b5b2ba8 --- /dev/null +++ b/src/zlua/lua/config.lua @@ -0,0 +1,54 @@ +local _pb = require "pb" +local class = {} +local logE = print +local _pb_path = "./Proto/pb/" +local function _regFile(file) + local ret = _pb.loadfile(_pb_path.. file) + if not ret then + logE(file .. " load failed :_regFile") + end +end + +function class.reg() + -- pbc reg auto-gen + _regFile('Cmd.pb') + _regFile('DataConfig.pb') + _regFile('Login.pb') + _regFile('MessageType.pb') + _regFile('Wrap.pb') + -- pbc reg auto-gen +end +local config_path = "%s.ini" +function class.EncodeConfig(msg , pbname , path) + if not msg then return end + path = path or string.format(config_path , pbname ) + local config = _pb.encode("pb." .. pbname , msg) + if not config or config == "" then + logE("EncodeConfig failed: " .. pbname , msg) + return + end + print("EncodeConfig len " .. #config) + local wf = io.open(path, "wb") + wf:write(config) + wf:close() +end +class.reg() +local item_list = { + {bp_name = "BP_MMOGameMode" , lua_name = "MMOGameMode"}, + {bp_name = "UI_FunBtnEntry" , lua_name = "GameWorld.UI.Entry.FunBtnEntry"}, +} +BP = { + item_list = item_list, + test_int = 123456, + test_str = "luaL_loadbufferx", +} + +function BP:getItemList() + return self.item_list +end +function BP.encode(path) + class.EncodeConfig(BP , "BPConfig" , path) +end +print("load file config.lua ") +return BP + diff --git a/src/zlua/lua/testdebug.lua b/src/zlua/lua/testdebug.lua new file mode 100644 index 0000000..7dec837 --- /dev/null +++ b/src/zlua/lua/testdebug.lua @@ -0,0 +1,19 @@ + +function printLua(t) + print("luaprint::",t , t.name) +end +function printLua2(t) + print("luaprint2::",t , t.name) + print(t.call()) +end +function printLua3(t) + print("luaprint3::",t , t.name) + print(debug.traceback()) +end +function callCPlusPlus(name,...) + _G[name](...) +end +t1 = {1} +t1.name = "t1" +t2 = {t1} +t2.name = "t2" \ No newline at end of file diff --git a/src/zlua/lua/testref.lua b/src/zlua/lua/testref.lua new file mode 100644 index 0000000..fc92c7f --- /dev/null +++ b/src/zlua/lua/testref.lua @@ -0,0 +1,16 @@ + +function testSetData() + c_setLuaData("ouczbs") +end + +function testGetData() + local data = c_getLuaData() + print("lua testGetData data = " .. data or "nil") +end +testSetData() +testGetData() +testGetData() +for k,v in pairs(_G) do + print(string.format("%s => %s\n",k,v)) +end +print(rawget(-1001000 , 1)) \ No newline at end of file diff --git a/src/zlua/proto/Cmd.proto b/src/zlua/proto/Cmd.proto new file mode 100644 index 0000000..bab5f17 --- /dev/null +++ b/src/zlua/proto/Cmd.proto @@ -0,0 +1,11 @@ + +syntax = "proto3"; +package pb; +option go_package = ".;pb"; +enum CMD +{ + CMD_INVALID = 0; + + xLoginAccountCmd = 1001; + xLoginAccountAckCmd = 1002; +} diff --git a/src/zlua/proto/DataConfig.proto b/src/zlua/proto/DataConfig.proto new file mode 100644 index 0000000..a28ff6a --- /dev/null +++ b/src/zlua/proto/DataConfig.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; +package pb; +option optimize_for = SPEED; + +message GuiConfig{ + message UIItem{ + int32 id = 1; + string layout = 3; + int32 layer = 4; + } + map item_map = 1; +} + +message BPConfig{ + message BPItem{ + string bp_name = 1; + string lua_name = 2; + } + repeated BPItem item_list = 1; +} +message Result{ + string bp_name = 1; + string lua_name = 2; +} +message TestConfig{ + int32 a = 1; + repeated string b = 2; + string c = 3; + repeated Result d = 4; +} \ No newline at end of file diff --git a/src/zlua/proto/Login.proto b/src/zlua/proto/Login.proto new file mode 100644 index 0000000..461cff5 --- /dev/null +++ b/src/zlua/proto/Login.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package pb; +option go_package = ".;pb"; + +message LoginAccountCmd{ + string account = 1; + string password = 2; +} + +message LoginAccountAckCmd{ + string result = 1; + bool success =2; + repeated int32 role_id_list = 3; +} \ No newline at end of file diff --git a/src/zlua/proto/MessageType.proto b/src/zlua/proto/MessageType.proto new file mode 100644 index 0000000..ba3f42a --- /dev/null +++ b/src/zlua/proto/MessageType.proto @@ -0,0 +1,10 @@ + +syntax = "proto3"; +package pb; +option go_package = ".;pb"; + +enum MT +{ + MT_INVALID = 0; + GameLogin = 1001; +} diff --git a/src/zlua/proto/Wrap.proto b/src/zlua/proto/Wrap.proto new file mode 100644 index 0000000..9ff3f6c --- /dev/null +++ b/src/zlua/proto/Wrap.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package pb; +option go_package = ".;pb"; + +message WrapMessage +{ + bytes content = 1; // 协议二进制 + int32 request =2; //请求码 + int32 response =3; //响应码 + int32 code = 4; //返回码 +} \ No newline at end of file diff --git a/src/zlua/proto/pb2cpp.bat b/src/zlua/proto/pb2cpp.bat new file mode 100644 index 0000000..99c419e --- /dev/null +++ b/src/zlua/proto/pb2cpp.bat @@ -0,0 +1,21 @@ +@echo off +setlocal EnableDelayedExpansion +set /p=exec.bat +set destPath=%2cpp/ +ECHO @echo on >>exec.bat +for %%i in (*.proto) do ( + set /p="protoc --cpp_out=%destPath% %%i "> exec.bat + + findstr /b /i import %%i >nul + if !errorlevel! equ 0 (set /p="--include_imports "> exec.bat) + + for /f tokens^=2*^ delims^=^" %%a in ('findstr /b /i import %%i') do ( + set /p= %%a > exec.bat + set /a wind+=1 + ) + ECHO.>> exec.bat +) +ECHO @echo off>> exec.bat +call exec.bat +del exec.bat +::pause \ No newline at end of file diff --git a/src/zlua/proto/pb2pbc.bat b/src/zlua/proto/pb2pbc.bat new file mode 100644 index 0000000..e803b50 --- /dev/null +++ b/src/zlua/proto/pb2pbc.bat @@ -0,0 +1,21 @@ +@echo off +setlocal EnableDelayedExpansion +set /p=exec.bat +set destPath=%2pb/ +ECHO @echo on >>exec.bat +for %%i in (*.proto) do ( + set /p="protoc --descriptor_set_out=%destPath%%%~ni.pb %%i "> exec.bat + + findstr /b /i import %%i >nul + if !errorlevel! equ 0 (set /p="--include_imports "> exec.bat) + + for /f tokens^=2*^ delims^=^" %%a in ('findstr /b /i import %%i') do ( + set /p= %%a > exec.bat + set /a wind+=1 + ) + ECHO.>> exec.bat +) +ECHO @echo off>> exec.bat +call exec.bat +del exec.bat +::pause \ No newline at end of file diff --git a/src/zlua/src/CLua.cpp b/src/zlua/src/CLua.cpp new file mode 100644 index 0000000..5b1790c --- /dev/null +++ b/src/zlua/src/CLua.cpp @@ -0,0 +1,20 @@ +// CLua.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// +#include "base/Degines.h" +#include "test/lua/luadebug.h" +using namespace std; + +int main() +{ + lua_State * L = luaL_newstate(); + luaL_openlibs(L); + //TestLuaSerialize(L); + //TestLuaRef(L); + TestLuaDebug(L); + cout << "Hello World!\n"; + //testing::InitGoogleTest(); + //int ret = RUN_ALL_TESTS(); + lua_close(L); + //TestMain(); + return 1; +} diff --git a/src/zlua/src/base/Degines.h b/src/zlua/src/base/Degines.h new file mode 100644 index 0000000..37ed6be --- /dev/null +++ b/src/zlua/src/base/Degines.h @@ -0,0 +1,14 @@ +#pragma once +//#include "pb.h" +extern "C" { +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" +} +#include +#include +#include +namespace clua { + const std::string path_config = "config/"; + const std::string lua_config = "lua/"; +} \ No newline at end of file diff --git a/src/zlua/src/test/api/luaapi.cpp b/src/zlua/src/test/api/luaapi.cpp new file mode 100644 index 0000000..bc1c512 --- /dev/null +++ b/src/zlua/src/test/api/luaapi.cpp @@ -0,0 +1,40 @@ +#include "luaapi.h" +#include "util/luautil.h" +int TestLuaApi(lua_State* L) { + if (!L) { + return -1; + } + lua_pushstring(L, "I am so cool~"); + lua_setglobal(L, "myStr"); + lua_pushnumber(L, 20); + lua_setglobal(L, "myInt"); + lua_getglobal(L, "myStr"); + lua_getglobal(L, "myInt"); + //3.ȡֵ + if (lua_isstring(L, -2)) { //жǷתΪstring + std::cout << lua_tostring(L, -2) << std::endl; //תΪstring + } + if (lua_isnumber(L, -1)) { + std::cout << lua_tonumber(L, -1) << std::endl; + } + const char* config = "./config.lua"; + int ret = luaL_loadfile(L, config); + if (ret != LUA_OK) { + std::cout << "load file failed : " << config << std::endl; + return -1; + } + //stackDump(L); + ///< ִluaļ + if (lua_pcall(L, 0, 0, 0)) + { + std::cerr << lua_tostring(L, -1) << std::endl; + } + lua_getglobal(L, "BP"); + lua_getfield(L, -1, "test_int"); + lua_getfield(L, -2, "test_str"); + lua_getfield(L, -3, "getItemList"); + stackDump(L); + int test_int = lua_tonumber(L, -3); + std::cout << "test_int : " << test_int << std::endl; + return 1; +} \ No newline at end of file diff --git a/src/zlua/src/test/api/luaapi.h b/src/zlua/src/test/api/luaapi.h new file mode 100644 index 0000000..2a09f61 --- /dev/null +++ b/src/zlua/src/test/api/luaapi.h @@ -0,0 +1,6 @@ +#pragma once +#include "base/Degines.h" +class luaapi +{ +}; + diff --git a/src/zlua/src/test/api/luaref.cpp b/src/zlua/src/test/api/luaref.cpp new file mode 100644 index 0000000..0fb32d0 --- /dev/null +++ b/src/zlua/src/test/api/luaref.cpp @@ -0,0 +1,40 @@ +#include "luaref.h" +#include "util/luautil.h" +using namespace std; +int g_ref = -1; +int setLuaData(lua_State* L) +{ + stackDump(L); + int ref = luaL_ref(L, LUA_REGISTRYINDEX); + g_ref = ref; + cout << "setLuaData ref= " << g_ref << endl; + stackDump(L); + return 1; +} +int getLuaData(lua_State* L) +{ + lua_rawgeti(L, LUA_REGISTRYINDEX, g_ref); + cout << "getLuaData ref= " << g_ref << endl; + luaL_unref(L, LUA_REGISTRYINDEX, g_ref); + stackDump(L); + return 1; +} +const string lua_ref_file = clua::lua_config + "testref.lua"; +int TestLuaRef(lua_State* L) { + lua_register(L, "c_setLuaData", setLuaData); + lua_register(L, "c_getLuaData", getLuaData); + const char* config = lua_ref_file.c_str(); + int ret = luaL_loadfile(L, config); + if (ret != LUA_OK) { + cout << "load file failed : " << config << endl; + return -1; + } + ///< ִluaļ + if (lua_pcall(L, 0, 1, 0)) + { + cerr << lua_tostring(L, -1) << endl; + return -1; + } + stackDump(L); + return 1; +} \ No newline at end of file diff --git a/src/zlua/src/test/api/luaref.h b/src/zlua/src/test/api/luaref.h new file mode 100644 index 0000000..2136ae8 --- /dev/null +++ b/src/zlua/src/test/api/luaref.h @@ -0,0 +1,7 @@ +#pragma once +#include "base/Degines.h" +int TestLuaRef(lua_State* L); +class luaref +{ +}; + diff --git a/src/zlua/src/test/lua/luadebug.cpp b/src/zlua/src/test/lua/luadebug.cpp new file mode 100644 index 0000000..ab13e11 --- /dev/null +++ b/src/zlua/src/test/lua/luadebug.cpp @@ -0,0 +1,39 @@ +#include "luadebug.h" +using namespace std; +const string lua_debug_file = clua::lua_config + "testdebug.lua"; + +void PrintLuaTable(lua_State* L, const char* funcname) { + lua_getglobal(L, funcname); + if (!lua_isnil(L, -1)) { + lua_pushvalue(L, -2); + if (lua_pcall(L, 1, 0, 0)) { + cerr << lua_tostring(L, -1) << endl; + lua_pop(L, 1); + } + } + else { + lua_pop(L, 1); + } +} +int TestLuaDebug(lua_State* L) { + const char* config = lua_debug_file.c_str(); + int ret = luaL_loadfile(L, config); + if (ret != LUA_OK) { + cout << "load file failed : " << config << endl; + return -1; + } + ///< ִ��lua�ļ� + if (lua_pcall(L, 0, 1, 0)) + { + cerr << lua_tostring(L, -1) << endl; + return -1; + } + lua_getglobal(L, "t1"); + lua_getglobal(L, "t2"); + for (int i = 0; i < 2; i++) { + PrintLuaTable(L, "printLua"); + PrintLuaTable(L, "printLua2"); + PrintLuaTable(L, "printLua3"); + } + return 1; +} \ No newline at end of file diff --git a/src/zlua/src/test/lua/luadebug.h b/src/zlua/src/test/lua/luadebug.h new file mode 100644 index 0000000..6ad2d3d --- /dev/null +++ b/src/zlua/src/test/lua/luadebug.h @@ -0,0 +1,7 @@ +#pragma once +#include "base/Degines.h" +int TestLuaDebug(lua_State* L); +class luadebug +{ +}; + diff --git a/src/zlua/src/test/pb/protobuf.cpp b/src/zlua/src/test/pb/protobuf.cpp new file mode 100644 index 0000000..02ba1d3 --- /dev/null +++ b/src/zlua/src/test/pb/protobuf.cpp @@ -0,0 +1,78 @@ + +#include "protobuf.h" +#include +#include +#include + +//#include "DataConfig.pb.h" +//#include "cpp/DataConfig.pb.h" +//#include "proto/DataConfig.pb.h" +#include "proto/DataConfig.pb.h" +/* +#include "../proto/cpp/DataConfig.pb.h" +#include "util/luautil.h" +using namespace pb; +using namespace std; +const string lua_file = clua::lua_config + "config.lua"; +const string bp_ini = clua::path_config + "BPConfig.ini"; +bool TestProtoSerialize(const char * outpath) { + BPConfig mConfig; + BPConfig_BPItem* bpitem1 = mConfig.add_item_list(); + bpitem1->set_bp_name("BP_MMOGameMode"); + bpitem1->set_lua_name("MMOGameMode"); + + BPConfig_BPItem* bpitem2 = mConfig.add_item_list(); + bpitem2->set_bp_name("UI_FunBtnEntry"); + bpitem2->set_lua_name("GameWorld.UI.Entry.FunBtnEntry"); + + fstream output(outpath, ios::out | ios::trunc | ios::binary); + mConfig.SerializeToOstream(&output); + return true; +} + +bool TestProtoUnSerialize(const char* inpath) { + BPConfig mConfig; + fstream in(inpath, std::ios::in | std::ios::binary); + in.seekg(0, std::ios_base::end); + std::streampos fileSize = in.tellg(); + in.seekg(0, std::ios_base::beg); + + cout << "fstream " << inpath << " size = " << fileSize << endl; + if (!mConfig.ParseFromIstream(&in)) { + return false; + } + cout << "TestProtoUnSerialize : " << mConfig.item_list_size() << endl; + return true; +} +void RegisterLuaLib(lua_State* L) +{ + luaL_requiref(L, "pb", luaopen_pb, 0); + luaL_requiref(L, "pb.io", luaopen_pb_io, 0); + luaL_requiref(L, "pb.slice", luaopen_pb_slice, 0); + luaL_requiref(L, "pb.buffer", luaopen_pb_buffer, 0); + luaL_requiref(L, "pb.conv", luaopen_pb_conv, 0); +} +int TestLuaSerialize(lua_State* L) { + RegisterLuaLib(L); + const char* config = lua_file.c_str(); + int ret = luaL_loadfile(L, config); + if (ret != LUA_OK) { + cout << "load file failed : " << config << endl; + return -1; + } + if (lua_pcall(L, 0, 1, 0)) + { + cerr << lua_tostring(L, -1) << endl; + return -1; + } + lua_getfield(L, -1, "encode"); + lua_pushfstring(L, bp_ini.c_str()); + if (lua_pcall(L, 1, 0, 0)) + { + cerr << lua_tostring(L, -1) << endl; + return -1; + } + stackDump(L); + return 1; +} +*/ \ No newline at end of file diff --git a/src/zlua/src/test/pb/protobuf.h b/src/zlua/src/test/pb/protobuf.h new file mode 100644 index 0000000..1b00cec --- /dev/null +++ b/src/zlua/src/test/pb/protobuf.h @@ -0,0 +1,9 @@ +#pragma once +#include "base/Degines.h" +#include "pb.h" +int TestLuaSerialize(lua_State* L); +void RegisterLuaLib(lua_State* L); +class protobuf +{ +}; + diff --git a/src/zlua/src/util/luautil.cpp b/src/zlua/src/util/luautil.cpp new file mode 100644 index 0000000..9430fb0 --- /dev/null +++ b/src/zlua/src/util/luautil.cpp @@ -0,0 +1,30 @@ +#include "luautil.h" +#include +int stackDump(lua_State* L) +{ + int i = 0; + int top = lua_gettop(L); // ȡջԪظ + std::cout << "ǰջ" << top << std::endl; + for (i = 1; i <= top; ++i) // ջÿԪء + { + int t = lua_type(L, i); // ȡԪص͡ + switch (t) + { + case LUA_TSTRING: // strings + std::cout << "" << i << " :" << lua_tostring(L, i); + break; + case LUA_TBOOLEAN: // bool + std::cout << "" << i << " :" << lua_toboolean(L, i) ? "true" : "false"; + break; + case LUA_TNUMBER: // number + std::cout << "" << i << " :" << lua_tonumber(L, i); + break; + default: // other values + std::cout << "" << i << " :" << lua_typename(L, t); + break; + } + std::cout << " "; + } + std::cout << std::endl; + return 1; +} diff --git a/src/zlua/src/util/luautil.h b/src/zlua/src/util/luautil.h new file mode 100644 index 0000000..4d33708 --- /dev/null +++ b/src/zlua/src/util/luautil.h @@ -0,0 +1,9 @@ +#pragma once +#include "base/Degines.h" + +int stackDump(lua_State* L); + +class luautil +{ +}; + diff --git a/src/zlua/xmake.lua b/src/zlua/xmake.lua new file mode 100644 index 0000000..617b769 --- /dev/null +++ b/src/zlua/xmake.lua @@ -0,0 +1,44 @@ + + + +target("zlua") + set_kind("binary") + add_rules("protobuf.cpp") + add_includedirs("src", {public = true}) + add_packages("lua","luasocket") + add_packages("protobuf-cpp","lua-protobuf") + + add_files("src/*.cpp","src/**/*.cpp") + add_files("proto/**.proto", {proto_rootdir = "src/zlua"}) + add_headerfiles("src/*.h","src/**/*.h") + + -- add_files("proto/*.proto", {rule = "protobuf.cpp", proto_rootdir = "proto"}) + -- add_files("proto/cpp/*.cc") + -- add_headerfiles("proto/cpp/*.h") + -- before_build(function (target) + -- os.cd("$(scriptdir)/proto") + -- os.execv("pb2pbc.bat") + -- os.exec("pb2cpp.bat") + -- target:add("files","cpp/*.cc") + -- target:add("headerfiles","cpp/*.h") + -- end ) + -- before_package(function(package) + -- print("before_package") + -- end) + -- before_install(function(package) + -- print("before_install") + -- end) + -- before_run(function(package) + -- print("before_run") + -- end) +-- add_rules("mode.debug", "mode.release") +-- add_requires("protobuf-cpp") + +-- target("test") +-- set_kind("binary") +-- set_languages("c++11") +-- add_packages("protobuf-cpp") +-- add_rules("protobuf.cpp") +-- add_files("src/*.cpp") +-- add_files("src/**.proto", {proto_rootdir = "src"}) + diff --git a/src/zplus/src/ZConfig/Config.h b/src/zplus/src/ZConfig/Config.h new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/src/zplus/src/ZConfig/Config.h @@ -0,0 +1 @@ +#pragma once diff --git a/src/zplus/src/ZConfig/Const.h b/src/zplus/src/ZConfig/Const.h new file mode 100644 index 0000000..6d370ea --- /dev/null +++ b/src/zplus/src/ZConfig/Const.h @@ -0,0 +1,3 @@ +#pragma once + +const uint32 MAX_PATH = 260; \ No newline at end of file diff --git a/src/zplus/src/ZConfig/Define.h b/src/zplus/src/ZConfig/Define.h new file mode 100644 index 0000000..90b6000 --- /dev/null +++ b/src/zplus/src/ZConfig/Define.h @@ -0,0 +1,22 @@ +#pragma once +#include +#define ZMAC_ASSERT(Expression)\ + {\ + assert(Expression);\ + } +#define R_ASSERT(x) \ + if(!x) return; +#define R_ASSERT_PTR(x)\ + if(!x) return nullptr; +// region MemoryManager +#define Z_NEW new +#define Z_DELETE delete +// region MemoryManager end + +// Define Engine API +#ifdef ZSYSTEM_EXPORTS + #define ZSYSTEM_API __declspec(dllexport) +#else + #define ZSYSTEM_API __declspec(dllimport) +#endif +// Define Engine API \ No newline at end of file diff --git a/src/zplus/src/ZConfig/Export.h b/src/zplus/src/ZConfig/Export.h new file mode 100644 index 0000000..762fbd1 --- /dev/null +++ b/src/zplus/src/ZConfig/Export.h @@ -0,0 +1,6 @@ +#pragma once +#include "Define.h" +#include "Type.h" +#include "Inline.h" +#include "Const.h" +#include "Config.h" \ No newline at end of file diff --git a/src/zplus/src/ZConfig/Inline.h b/src/zplus/src/ZConfig/Inline.h new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/src/zplus/src/ZConfig/Inline.h @@ -0,0 +1 @@ +#pragma once diff --git a/src/zplus/src/ZConfig/Type.h b/src/zplus/src/ZConfig/Type.h new file mode 100644 index 0000000..0fc79a7 --- /dev/null +++ b/src/zplus/src/ZConfig/Type.h @@ -0,0 +1,7 @@ +#pragma once + +typedef __int64 int64; +typedef __int32 int32; +typedef unsigned char byte; +typedef unsigned __int32 uint32; +typedef unsigned __int64 uint64; \ No newline at end of file diff --git a/src/zplus/src/ZGrammar/Class.h b/src/zplus/src/ZGrammar/Class.h new file mode 100644 index 0000000..45b6062 --- /dev/null +++ b/src/zplus/src/ZGrammar/Class.h @@ -0,0 +1,87 @@ +#pragma once +#include +#include "ZTool/log.h" +using namespace std; + +class TPoint { +public: + static int static_int_a; + int x; + int y; + bool c = false; + TPoint() { + x = 0; + y = 0; + } + TPoint(int x, int y) { + this->x = x; + this->y = y; + } + static int TestStaticFunction() { + return static_int_a; + } + int GetStatic() { + return static_int_a; + } + virtual void Testvirtual() { + + } + virtual void Testvirtua2() { + + } +private: + void TestPrivate() { + LOG_INFO("call TestPrivate Function"); + } +}; +class TPointSon : public TPoint { +public: + int s = 1; + TPointSon(int x, int y) { + this->x = x; + this->y = y; + } + void SonFunction() { + //TestPrivate(); + } +}; +int TPoint::static_int_a = 0; +static int static_int_a = -1; + +void TestMemory() { + //ڴ沼 + TPoint p1(1, 2),p2(2,4); + TPointSon ps(2 , 3); + uint8_t* ptr_u = (uint8_t*) &ps; + TPoint* p3 = (TPoint*)ptr_u; + LOG_INFO("\t\t TestClass"); + LOG_INFO("{} {}", typeid(p1).name(),typeid(ps).name()); + LOG_INFO("class size = {} object size = {}", sizeof(TPoint), sizeof(p1)); + LOG_INFO("class static addr = {} static addr = {}", (void*)&TPoint::static_int_a, (void*)&static_int_a); + auto a = 1; + auto b = FPTR(&TPoint::TestStaticFunction); + TPoint::TestStaticFunction(); + p1.Testvirtual(); + typedef void (TPoint::* FuncPointer)(); + FuncPointer fp1 = &TPoint::Testvirtual; + FuncPointer fp2 = &TPoint::Testvirtua2; + (p1.*fp1)(); + (p2.*fp2)(); + p2.Testvirtua2(); + std::cout << &TPoint::TestStaticFunction << &TPoint::Testvirtual << &TPoint::Testvirtua2; + //LOG_INFO("class static function addr = {} class virtual function addr = = {}", FPTR(&TPoint::TestStaticFunction), a); + //LOG_INFO("class static function addr = {} class virtual function addr = = {}", LPTR(&TPoint::TestStaticFunction), LPTR(&TPoint::Testvirtual)); + //ӡڴ + bool* ip = (bool*)&p1; + //LOG_INFO("object hex addr = {}", *(int*)ip); + for (int i = 0; i < sizeof(TPoint); i++) { + if (i % 4 == 0) { + //LOG_INFO("object hex addr = {}{}", *(int*)(ip + i),(int*) * (int*)(ip + i)); + } + //LOG_INFO(" {} ", *(ip + i)); + } + LOG_INFO(""); +} +void TestClass() { + TestMemory(); +} \ No newline at end of file diff --git a/src/zplus/src/ZGrammar/Grammar.h b/src/zplus/src/ZGrammar/Grammar.h new file mode 100644 index 0000000..973a172 --- /dev/null +++ b/src/zplus/src/ZGrammar/Grammar.h @@ -0,0 +1,14 @@ +#pragma once +#include "Template .h" +#include "Parameter.h" +#include "Class.h" + +#include +using namespace std; +void TestGrammer() { + cout << "\t TestGrammer" << endl; + //TestTemplate(); + TestParmeter(); + TestClass(); + //TestReflex(); +} \ No newline at end of file diff --git a/src/zplus/src/ZGrammar/Parameter.h b/src/zplus/src/ZGrammar/Parameter.h new file mode 100644 index 0000000..d30c8c0 --- /dev/null +++ b/src/zplus/src/ZGrammar/Parameter.h @@ -0,0 +1,95 @@ +#pragma once +#include +#include +#include +using namespace std; +class Object { +public: + int value = 0; +}; +class Rect +{ +public: + Object obj; +public: + int a; +public: + Rect() { + a = 0; + } + Rect(int _a) { + a = _a; + } + Object ValueReturn() { + return obj; + } + Object& ReferenceReturn() { + return obj; + } + Object* PointReturn() { + return &obj; + } +}; +int change(int a) { + return a - 100; +} +//ֵ +void ValuePassing(Rect rc ,int ai) { + int a = rc.a; + rc.a = change(rc.a); + Object obj = rc.ValueReturn(); + obj.value = change(obj.value); + ai = change(ai); + cout << "ValuePassing change" << endl; + cout << "parmar addr = " << &rc << " , return addr = " << &rc.obj <<" : " << &obj << endl; + cout << "parmar a = " << a << " :" << rc.a << " , return value = " << rc.obj.value << " :" << obj.value << endl; + cout << "parmar ai = " << ai << endl; + +} +//ô +void ReferencePassing(Rect& rc, int& ai) { + int a = rc.a; + rc.a = change(rc.a); + Object& obj = rc.ReferenceReturn(); + obj.value = change(obj.value); + ai = change(ai); + cout << "ReferencePassing change" << endl; + cout << "parmar addr = " << &rc << " , return addr = " << &rc.obj << " : " << &obj << endl; + cout << "parmar a = " << a << " :" << rc.a << " , return value = " << rc.obj.value << " :" << obj.value << endl; + cout << "parmar ai = " << ai << endl; +} +//ָ봫 +void PointPassing(Rect* rc_ptr, int* ai) { + Rect& rc = *rc_ptr; + int a = rc.a; + rc.a = change(rc.a); + Object& obj = *rc.PointReturn(); + obj.value = change(obj.value); + *ai = change(*ai); + cout << "PointPassing change" << endl; + cout << "parmar addr = " << &rc << " , return addr = " << &rc.obj << " : " << &obj << endl; + cout << "parmar a = " << a << " :" << rc.a << " , return value = " << rc.obj.value << " :" << obj.value << endl; + cout << "parmar ai = " << *ai << endl; +} +void pt(int a , int b , int c , string str) { + cout << "parameter " << a << endl; +} +//չ +template +void print(int a , TArgs... Args) +{ + cout << "parameter " << a << endl; + pt(Args...); +} +void TestParmeter() +{ + //ʵκβ + cout << "\t\t TestParmeter" << endl; + Rect rc; + int ai = 1; + ValuePassing(rc , ai); + ReferencePassing(rc , ai); + PointPassing(&rc , &ai); + + print(1, 2, 3, 4, "str_5"); +} \ No newline at end of file diff --git a/src/zplus/src/ZGrammar/Reflex.h b/src/zplus/src/ZGrammar/Reflex.h new file mode 100644 index 0000000..62f8006 --- /dev/null +++ b/src/zplus/src/ZGrammar/Reflex.h @@ -0,0 +1,41 @@ +#pragma once +#pragma once +#include + +using namespace std; + +class TPoint { +public: + int a; + int b; + + TPoint() { + a = 0; + b = 0; + } + TPoint(int a, int b) { + this -> a = a; + this -> b = b; + } + static int getA() { + return 0; + } + int getB() { + return b; + } + virtual void Testvirtual() { + + } +}; + +void TestReflex() { + TPoint p1; + TPoint p2; + int x = 0; + // 麯 ̬ + cout << "\t\t TestReflex" << endl; + cout << "size = " << sizeof(p1) << endl; + cout << "size = " << sizeof(TPoint) << endl; + cout<< " addr p1 = " << &p1 << "addr p2 = " << &p2 << " class tp = " << endl; + cout << " addr p1 = " << *(int*)&p1 << "addr p2 = " << *(int*)&p2 << endl; +} \ No newline at end of file diff --git a/src/zplus/src/ZGrammar/Template .h b/src/zplus/src/ZGrammar/Template .h new file mode 100644 index 0000000..7f7a04d --- /dev/null +++ b/src/zplus/src/ZGrammar/Template .h @@ -0,0 +1,45 @@ +#pragma once +#include +#include +using namespace std; + +template class Test { +public: + void f() { + cout << "My Type is: " << typeid(*this).name() << endl; + } +}; +template +void Swap(T& a, T& b) +{ + T c = a; + a = b; + b = c; +} + +void Template2() +{ + void (*FPii)(int&, int&); + + FPii = Swap; //ָFPii + + void (*FPff)(float&, float&); + + FPff = Swap; //ָFPff + + cout << reinterpret_cast(FPii) << endl; + cout << reinterpret_cast(FPff) << endl; +} +void Template1() { + Test().f(); + Test().f(); + + cout.setf(ios::boolalpha); + + cout << bool(typeid(Test) == typeid(Test)) << endl; +} +void TestTemplate() { + cout << "\t\t TestTemplate" << endl; + Template1(); + Template2(); +} \ No newline at end of file diff --git a/src/zplus/src/ZSort/BubbleSort.h b/src/zplus/src/ZSort/BubbleSort.h new file mode 100644 index 0000000..a12c680 --- /dev/null +++ b/src/zplus/src/ZSort/BubbleSort.h @@ -0,0 +1,34 @@ +#pragma once +#include "type.h" +class BubbleSort : public ISort{ +public: + + void Desc(T tlist[], int len) { + for (int i = 0; i < len - 1; i++) { + bool ok = true; + for (int j = 0; j < len - 1 - i; j++) { + if (tlist[j] < tlist[j+1]) { + T t1 = tlist[j]; + tlist[j] = tlist[j+1]; + tlist[j+1] = t1; + ok = false; + } + } + if (ok) return; + } + } + void Inc(T tlist[], int len) { + for (int i = 0; i < len - 1; i++) { + bool ok = true; + for (int j = 0; j < len - i - 1; j++) { + if (tlist[j] > tlist[j+1]) { + T t1 = tlist[j]; + tlist[j] = tlist[j+1]; + tlist[j+1] = t1; + ok = false; + } + } + if (ok) return; + } + } +}; diff --git a/src/zplus/src/ZSort/BucketSort.h b/src/zplus/src/ZSort/BucketSort.h new file mode 100644 index 0000000..ae07aa2 --- /dev/null +++ b/src/zplus/src/ZSort/BucketSort.h @@ -0,0 +1,98 @@ + +#pragma once +#include "type.h" + +class Bucket { +private: + +public: + Bucket* next = nullptr; + Bucket* prev = nullptr; + bool isEmpty = true; + T value = 0; + Bucket() {}; + Bucket(T _value) { + value = _value; + isEmpty = false; + } + void push(T tvalue ,bool isInc) { + if (isEmpty) { + value = tvalue; + isEmpty = false; + return; + } + if ((isInc && tvalue > value) || (!isInc && tvalue < value)) { + if (next) { + next->push(tvalue, isInc); + } + else { + next = new Bucket(tvalue);//ջʹãnew + next->prev = this; + } + } + else { + if (prev) { + prev->next = new Bucket(tvalue); + prev->next->next = this; + prev->next->prev = prev; + prev = prev->next; + } + else { + T t = value; + value = tvalue; + push(t , isInc); + } + } + } +}; +class BucketSort : public ISort { + private: + bool isInc = false; + public: + void bucket(T tlist[], int len) { + int bucketNum = len / 2; + T min = tlist[0], max = tlist[0]; + for (int i = 0; i < len; i++) { + if (min > tlist[i]) { + min = tlist[i]; + } + else if (max < tlist[i]) { + max = tlist[i]; + } + } + int gap = (max - min + 1) / bucketNum; + bucketNum++; + Bucket* bucketList = new Bucket[bucketNum]; + for (int i = 0; i < len; i++) { + int j = (tlist[i] - min ) / gap; + bucketList[j].push(tlist[i] , isInc); + int a = 1; + } + if (isInc) { + for (int i = 0, j = 0; i < bucketNum; i++) { + Bucket* bucket = &bucketList[i]; + while (bucket && !bucket->isEmpty) { + tlist[j++] = bucket->value; + bucket = bucket->next; + } + } + } + else { + for (int i = bucketNum - 1, j = 0; i >=0; i--) { + Bucket* bucket = &bucketList[i]; + while (bucket && !bucket->isEmpty) { + tlist[j++] = bucket->value; + bucket = bucket->next; + } + } + } + } + void Desc(T tlist[], int len) { + isInc = false; + bucket(tlist, len); + } + void Inc(T tlist[], int len) { + isInc = true; + bucket(tlist, len); + } + }; diff --git a/src/zplus/src/ZSort/CountSort.h b/src/zplus/src/ZSort/CountSort.h new file mode 100644 index 0000000..e269c7a --- /dev/null +++ b/src/zplus/src/ZSort/CountSort.h @@ -0,0 +1,49 @@ +#pragma once +#include "type.h" +class CountSort : public ISort { +private: + bool isInc = false; +public: + void count(T tlist[], int len) { + T min = tlist[0], max = tlist[0]; + for (int i = 0; i < len; i++) { + if (min > tlist[i]) { + min = tlist[i]; + } + else if (max < tlist[i]) { + max = tlist[i]; + } + } + T* countlist = new T[max - min + 1]; + for (int i = 0; i < max - min + 1; i++) { + countlist[i] = 0; + } + for (int i = 0; i < len; i++) { + countlist[tlist[i] - min]++; + } + if (isInc) { + for (int i = 0, j = 0; i < max - min + 1; i++) { + while (countlist[i]) { + countlist[i]--; + tlist[j++] = i + min; + } + } + } + else { + for (int i = 0, j = len-1; i < max - min + 1; i++) { + while (countlist[i]) { + countlist[i]--; + tlist[j--] = i + min; + } + } + } + } + void Desc(T tlist[], int len) { + isInc = false; + count(tlist, len); + } + void Inc(T tlist[], int len) { + isInc = true; + count(tlist, len); + } +}; diff --git a/src/zplus/src/ZSort/HeapSort.h b/src/zplus/src/ZSort/HeapSort.h new file mode 100644 index 0000000..944a4cf --- /dev/null +++ b/src/zplus/src/ZSort/HeapSort.h @@ -0,0 +1,38 @@ +#pragma once +#include "type.h" +class HeapSort : public ISort { +private: + bool isInc = false; +public: + void swap(T tlist[] , int i , int len) { + int j = i * 2 + 1; + while (j < len) { + if ((tlist[j] > tlist[i] && isInc) || (tlist[j] < tlist[i] && !isInc)) { + T t = tlist[i]; + tlist[i] = tlist[j]; + tlist[j] = t; + swap(tlist , j , len); + } + j++; + } + } + void heap(T tlist[] , int len) { + if (len <= 1)return; + int tops = (len - 1) / 2; + for (int i = tops; i >= 0; i--) { + swap(tlist, i, len); + } + T t = tlist[0]; + tlist[0] = tlist[len - 1]; + tlist[len - 1] = t; + heap(tlist, len - 1); + } + void Desc(T tlist[] , int len) { + isInc = false; + heap(tlist, len); + } + void Inc(T tlist[], int len) { + isInc = true; + heap(tlist, len); + } +}; \ No newline at end of file diff --git a/src/zplus/src/ZSort/InsertSort.h b/src/zplus/src/ZSort/InsertSort.h new file mode 100644 index 0000000..d6f2792 --- /dev/null +++ b/src/zplus/src/ZSort/InsertSort.h @@ -0,0 +1,27 @@ +#pragma once +#include "type.h" +class InsertSort : public ISort { +public: + void Desc(T tlist[], int len) { + for (int i = 1; i < len; i++) { + int j = i; + T ti = tlist[i]; + while (j > 0 && ti > tlist[j - 1]) { + tlist[j] = tlist[j - 1]; + j--; + } + tlist[j] = ti; + } + } + void Inc(T tlist[], int len) { + for (int i = 1; i < len; i++) { + int j = i - 1; + T ti = tlist[i]; + while (j >= 0 && ti < tlist[j]) { + tlist[j + 1] = tlist[j]; + j--; + } + tlist[j + 1] = ti; + } + } +}; diff --git a/src/zplus/src/ZSort/MergeSort.h b/src/zplus/src/ZSort/MergeSort.h new file mode 100644 index 0000000..a8ab055 --- /dev/null +++ b/src/zplus/src/ZSort/MergeSort.h @@ -0,0 +1,52 @@ +#pragma once +#include "type.h" +class MergeSort : public ISort { +private: + bool isInc = false; +public: + + void merge(T tlist[],int left, int mid , int right) { + int i = left, j = mid; + T* copylist = new T[right - left], k = 0; + while (i < mid && j < right) { + if (isInc) { + if (tlist[i] < tlist[j]) { + copylist[k++] = tlist[i++]; + } + else { + copylist[k++] = tlist[j++]; + } + }else if(tlist[i] > tlist[j]) { + copylist[k++] = tlist[i++]; + } + else { + copylist[k++] = tlist[j++]; + } + } + while (i < mid) { + copylist[k++] = tlist[i++]; + } + while (j < right) { + copylist[k++] = tlist[j++]; + } + for (i = left, k = 0; i < right; i++) { + tlist[i] = copylist[k++]; + } + } + void divid(T tlist[],int left , int right) { + if (right - left > 1) {//鳤ȴһ + int mid = (left + right) / 2; + divid(tlist, left, mid); + divid(tlist, mid, right); + merge(tlist, left, mid, right); + } + } + void Desc(T tlist[], int len) { + isInc = false; + divid(tlist, 0, len); + } + void Inc(T tlist[], int len) { + isInc = true; + divid(tlist, 0, len); + } +}; diff --git a/src/zplus/src/ZSort/QuickSort.h b/src/zplus/src/ZSort/QuickSort.h new file mode 100644 index 0000000..119c45b --- /dev/null +++ b/src/zplus/src/ZSort/QuickSort.h @@ -0,0 +1,36 @@ +#pragma once +#include "type.h" +class QuickSort : public ISort { +private: + bool isInc = false; +public: + void divid(T tlist[], int left, int right) { + if (right - left > 1) {//鳤ȴһ + int pivot = left; + T tp = tlist[pivot]; + int i = right - 1; + while (i > pivot) { + if ((isInc && tp > tlist[i]) || (!isInc && tp < tlist[i])) { + tlist[pivot] = tlist[i]; + tlist[i] = tlist[pivot + 1]; + pivot++; + + } + else { + i--; + } + } + tlist[pivot] = tp; + divid(tlist, left, pivot); + divid(tlist, pivot + 1, right); + } + } + void Desc(T tlist[], int len) { + isInc = false; + divid(tlist, 0, len); + } + void Inc(T tlist[], int len) { + isInc = true; + divid(tlist, 0, len); + } +}; diff --git a/src/zplus/src/ZSort/RadixSort.h b/src/zplus/src/ZSort/RadixSort.h new file mode 100644 index 0000000..a5659cc --- /dev/null +++ b/src/zplus/src/ZSort/RadixSort.h @@ -0,0 +1,41 @@ +#pragma once +#include "type.h" + +class RadixSort : public ISort { +public: + bool isInc = false; + void radix(T tlist[], int len) { + int count[11] = { 0 , 0 ,0}; + int k = 1; + T* copylist = new T[len]; + while (count[1] < len) { + for (int i = 0; i < 11; i++)count[i] = 0; + for (int i = 0; i < len; i++) { + int j = (tlist[i] / k) % 10 + 1; + count[j]++; + } + for (int i = 1; i < 11; i++)count[i] += count[i - 1]; + for (int i = 0; i < len; i++) { + int j = (tlist[i] / k) % 10; + copylist[count[j]++] = tlist[i]; + } + for (int i = 0; i < len; i++) { + tlist[i] = copylist[i]; + } + k *= 10; + } + if (!isInc) { + for (int i = 0; i < len; i++) { + tlist[i] = copylist[len - i - 1]; + } + } + } + void Desc(T tlist[], int len) { + isInc = false; + radix(tlist, len); + } + void Inc(T tlist[], int len) { + isInc = true; + radix(tlist, len); + } +}; diff --git a/src/zplus/src/ZSort/SelectSort.h b/src/zplus/src/ZSort/SelectSort.h new file mode 100644 index 0000000..f0b2d3a --- /dev/null +++ b/src/zplus/src/ZSort/SelectSort.h @@ -0,0 +1,29 @@ +#pragma once +#include "type.h" +class SelectSort :public ISort { +public: + void Desc(T tlist[], int len) { + for (int i = 0; i < len; i++) { + int maxIndex = i; + for (int j = i + 1; j < len; j++) { + if (tlist[maxIndex] < tlist[j]) { + maxIndex = j; + } + } + T t1 = tlist[maxIndex]; + tlist[maxIndex] = tlist[i]; + tlist[i] = t1; + } + } + void Inc(T tlist[], int len) { + for (int i = 0; i < len; i++) { + for (int j = i + 1; j < len; j++) { + if (tlist[i] > tlist[j]) { + T t1 = tlist[i]; + tlist[i] = tlist[j]; + tlist[j] = t1; + } + } + } + } +}; \ No newline at end of file diff --git a/src/zplus/src/ZSort/ShellSort.h b/src/zplus/src/ZSort/ShellSort.h new file mode 100644 index 0000000..b845624 --- /dev/null +++ b/src/zplus/src/ZSort/ShellSort.h @@ -0,0 +1,37 @@ +#pragma once +#include "type.h" +class ShellSort : public ISort { +public: + void Desc(T tlist[], int len) { + int gap = len / 2; + while (gap) { + for (int i = 0; i < gap; i++) { + for (int j = gap; j < len; j += gap) { + T tj = tlist[j]; + int k = j - gap; + while (k >= 0 && tj > tlist[k]) { + tlist[k + gap] = tlist[k]; + k -= gap; + } + tlist[k + gap] = tj; + } + } + gap = gap / 2; + } + } + void Inc(T tlist[], int len) { + int gap = len / 2; + while (gap) { + for (int i = gap; i < len; i++) { + T ti = tlist[i]; + int j = i - gap; + while (j >= 0 && ti < tlist[j]) { + tlist[j + gap] = tlist[j]; + j -= gap; + } + tlist[j + gap] = ti; + } + gap = gap / 2; + } + } +}; diff --git a/src/zplus/src/ZSort/Sort.h b/src/zplus/src/ZSort/Sort.h new file mode 100644 index 0000000..ee2f0fd --- /dev/null +++ b/src/zplus/src/ZSort/Sort.h @@ -0,0 +1,95 @@ +#pragma once +#include "BubbleSort.h" +#include "SelectSort.h" +#include "InsertSort.h" +#include "ShellSort.h" +#include "MergeSort.h" +#include "QuickSort.h" +#include "HeapSort.h" +#include "CountSort.h" +#include "BucketSort.h" +#include "RadixSort.h" +#include +using namespace std; + +template +void printList(T tlist[] , int len) { + for (int i = 0; i < len;i++) { + cout << tlist[i] << ' '; + } + cout << endl; +} +void TestISort(ISort &st) { + int a[] = { 333,12, 2,23,0,456 ,35, 16, 1,39, 120,7, 258,4 ,78}; + int l = sizeof(a) / 4; + cout << " **********************" << endl; + cout << "size = " << l << endl; + printList(a, l); + st.Desc(a, l); + printList(a, l); + st.Inc(a, l); + printList(a, l); + cout << " **********************" << endl; +} +void TestBubbleSort() { + cout<<" TestBubbleSort " << endl; + BubbleSort bs = BubbleSort(); + TestISort(bs); +}; +void TestSelectSort() { + cout << " TestSelectSort " << endl; + SelectSort bs = SelectSort(); + TestISort(bs); +}; +void TestInsertSort() { + cout << " TestInsertSort " << endl; + InsertSort bs = InsertSort(); + TestISort(bs); +} +void TestShellSort() { + cout << " TestShellSort " << endl; + ShellSort bs = ShellSort(); + TestISort(bs); +} +void TestMergeSort() { + cout << " TestMergeSort " << endl; + MergeSort bs = MergeSort(); + TestISort(bs); +} +void TestQuickSort() { + cout << " TestQuickSort " << endl; + QuickSort bs = QuickSort(); + TestISort(bs); +} +void TestHeapSort() { + cout << " TestHeapSort " << endl; + HeapSort bs = HeapSort(); + TestISort(bs); +} +void TestCountSort() { + cout << " TestCountSort " << endl; + CountSort bs = CountSort(); + TestISort(bs); +} +void TestBucketSort() { + cout << " TestBucketSort " << endl; + BucketSort bs = BucketSort(); + TestISort(bs); +} +void TestRadixSort() { + cout << " TestRadixSort " << endl; + RadixSort bs = RadixSort(); + TestISort(bs); +} +void TestSort() { + TestBubbleSort(); + TestSelectSort(); + TestInsertSort(); + TestShellSort(); + TestMergeSort(); + TestQuickSort(); + TestHeapSort(); + TestCountSort(); + TestBucketSort(); + TestRadixSort(); +} \ No newline at end of file diff --git a/src/zplus/src/ZSort/type.h b/src/zplus/src/ZSort/type.h new file mode 100644 index 0000000..3700f20 --- /dev/null +++ b/src/zplus/src/ZSort/type.h @@ -0,0 +1,21 @@ +#pragma once +#include +using namespace std; +typedef int T; +class ISort +{ +public: + virtual void Desc(T tlist[], int len) { + + } + virtual void Inc(T tlist[], int len) { + + } +}; +void printPoint(T *tpoint , int len) { + for (int i = 0; i < len;i++) { + cout << *tpoint << " "; + tpoint++; + } + cout << endl; +} \ No newline at end of file diff --git a/src/zplus/src/ZTest/TestConst.cpp b/src/zplus/src/ZTest/TestConst.cpp new file mode 100644 index 0000000..98a709c --- /dev/null +++ b/src/zplus/src/ZTest/TestConst.cpp @@ -0,0 +1,37 @@ +#include "TestConst.h" + +int TestConstMain() { + /* + int a = 0; + const int a1 = 1; + int const a2 = 2; + + const int* b1; + int* const b2 = &a; + b1 = &a1; + b1 = &a2; + + const int* const c1 = &a; + // errors + //a1 = 1;//a2 = 2; + //*b1 = 3;//b2 = &a2; + //c1 = &a2;*c1 = a1; + + TestConst t1; + t1.a = 1; + t1.n = {}; + t1.p = &t1.n; + const TestConst t2; + + const TestConst* tc4; + TestConst* const tc3 = &t1; + tc4 = &t1; + tc4 = &t2; + //tc4->a = 2; + //t2.a = 2; + tc3->a = 1; + //tc3 = &t2; + int a23[5]{}; + */ + return 1; +} \ No newline at end of file diff --git a/src/zplus/src/ZTest/TestConst.h b/src/zplus/src/ZTest/TestConst.h new file mode 100644 index 0000000..536fd78 --- /dev/null +++ b/src/zplus/src/ZTest/TestConst.h @@ -0,0 +1,17 @@ +#pragma once +struct Node { + Node* next; + int v; +}; +class TestConst +{ +public: + TestConst() {}; +public: + int a = 1; + Node* p; + Node n; +}; + +int TestConstMain(); + diff --git a/src/zplus/src/ZTest/TestDelegate.cpp b/src/zplus/src/ZTest/TestDelegate.cpp new file mode 100644 index 0000000..c75cd69 --- /dev/null +++ b/src/zplus/src/ZTest/TestDelegate.cpp @@ -0,0 +1,19 @@ +#include "TestDelegate.h" +void PrintAdd3(int a, int b) +{ + cout << "Call PrintAdd, Value = " << a + b << endl; +} +int TestDelegateMain() +{ + /* + vector tslist; + TestStruct ts; + tslist.push_back(ts); + A a; + B* b = new B(); + ts.OnOne.Bind(&a, &A::PrintAdd); + ts.OnOne(5,10); + delete b; + */ + return 0; +} \ No newline at end of file diff --git a/src/zplus/src/ZTest/TestDelegate.h b/src/zplus/src/ZTest/TestDelegate.h new file mode 100644 index 0000000..750048c --- /dev/null +++ b/src/zplus/src/ZTest/TestDelegate.h @@ -0,0 +1,30 @@ +#pragma once +#include "ZTool/delegate.h" +#include +using namespace std; + +class A +{ +public: + void PrintAdd(int a, int b) + { + cout << "Call PrintAdd By Class A, Value = " << a + b << endl; + } +}; + +class B +{ +public: + void PrintAdd(int a, int b) + { + cout << "Call PrintAdd By Class B, Value = " << a + b << endl; + } +}; + +DECLARE_FUNCTION_DELEGATE(FAddDelegate, void,int, int) + +struct TestStruct { + //FAddDelegate OnOne; +}; +int TestDelegateMain(); + diff --git a/src/zplus/src/ZTool/Timer.h b/src/zplus/src/ZTool/Timer.h new file mode 100644 index 0000000..2ea7cf2 --- /dev/null +++ b/src/zplus/src/ZTool/Timer.h @@ -0,0 +1,31 @@ +#pragma once +# include +using namespace std::chrono; +class TimerWatch { +public: + // ʱ + TimerWatch() : m_start(system_clock::time_point::min()) { } + // ʱ + void Clear() { + m_start = system_clock::time_point::min(); + } + // ʱڼʱ򷵻true + bool IsStarted() const { + return (m_start.time_since_epoch() != system_clock::duration(0)); + } + // ʱ + void Start() { + m_start = system_clock::now(); + } + // õԼʱʼĺֵ + unsigned long GetMs() { + if (IsStarted()) { + system_clock::duration diff; + diff = system_clock::now() - m_start; + return (unsigned)(duration_cast(diff).count()); + } + return 0; + } +private: + system_clock::time_point m_start; +}; \ No newline at end of file diff --git a/src/zplus/src/ZTool/delegate.h b/src/zplus/src/ZTool/delegate.h new file mode 100644 index 0000000..fad3efc --- /dev/null +++ b/src/zplus/src/ZTool/delegate.h @@ -0,0 +1,275 @@ +#pragma once +#ifndef DELEGATE_H +#define DELEGATE_H + +#include +#include + +#ifndef DECLARE_FUNCTION_DELEGATE +#define DECLARE_FUNCTION_DELEGATE(DelegateName, ReturnValueType, ...) typedef std::FunDelegate (DelegateName); +#define DECLARE_FUNCTION_DELEGATE_NO_PARAMETER(DelegateName, ReturnValueType) typedef std::FunDelegate (DelegateName); +#endif + +#ifndef DECLARE_FUNCTION_MULTICAST_DELEGATE +#define DECLARE_FUNCTION_MULTICAST_DELEGATE(DelegateName, ...) typedef std::MultiDelegate<__VA_ARGS__> (DelegateName); +#define DECLARE_FUNCTION_MULTICAST_DELEGATE_NO_PARAMETER(DelegateName) typedef std::FunDelegate (DelegateName); +#endif + +namespace std +{ + class DelegateInterface final + { + public: + template + friend class FunDelegate; + + template + friend class MultiDelegate; + + private: + template + struct IDelegate + { + virtual ReturnT operator() (ArgsT... args) = 0; + virtual ~IDelegate() { }; + }; + + //Աģ + template + class DynamicDelegate : public IDelegate + { + public: + typedef ReturnT(ClassT::* FunT) (ArgsT...); + + DynamicDelegate() = delete; + explicit DynamicDelegate(ClassT* objPtr, FunT funPtr) :obj(objPtr), func(funPtr) { }; + ~DynamicDelegate() { }; + + virtual ReturnT operator() (ArgsT... args) override + { + return (obj->*func)(args...); + } + + ClassT* obj; + FunT func; + }; + + //dzԱģ + template + class StaticDelegate : public IDelegate + { + public: + typedef ReturnT(*FunT) (ArgsT...); + + StaticDelegate() = delete; + explicit StaticDelegate(FunT funPtr) :func(funPtr) { }; + ~StaticDelegate() { }; + + virtual ReturnT operator() (ArgsT... args) override + { + return (*func)(args...); + } + + FunT func; + }; + }; + + template + class FunDelegate final + { + public: + explicit FunDelegate(); + explicit FunDelegate(typename DelegateInterface::StaticDelegate::FunT funPtr); + + template + explicit FunDelegate(ClassT* obj, typename DelegateInterface::DynamicDelegate::FunT funPtr); + + ~FunDelegate(); + + void Bind(typename DelegateInterface::StaticDelegate::FunT funPtr); + + template + void Bind(ClassT* obj, typename DelegateInterface::DynamicDelegate::FunT funPtr); + + ReturnT Invoke(ArgsT... args); + ReturnT operator() (ArgsT... args); + + void Clear(); + private: + std::unique_ptr > dlgtPtr; + }; + + template + class MultiDelegate final + { + public: + MultiDelegate(); + ~MultiDelegate(); + + void AddFunc(typename DelegateInterface::StaticDelegate::FunT funPtr); + + template + void AddFunc(ClassT* obj, typename DelegateInterface::DynamicDelegate::FunT funPtr); + + void BroadCast(ArgsT... args); + void operator() (ArgsT... args); + + bool RemoveFunc(typename DelegateInterface::StaticDelegate::FunT funPtr); + + template + bool RemoveFunc(ClassT* obj, typename DelegateInterface::DynamicDelegate::FunT funPtr); + + void Clear(); + private: + std::vector > > dlgtPtrArray; + }; +} + +template +inline std::FunDelegate::FunDelegate() +{ + +} + +template +inline std::FunDelegate::FunDelegate(typename DelegateInterface::StaticDelegate::FunT funPtr) +{ + Bind(funPtr); +} + +template +template +inline std::FunDelegate::FunDelegate(ClassT* obj, typename DelegateInterface::DynamicDelegate::FunT funPtr) +{ + Bind(obj, funPtr); +} + +template +inline std::FunDelegate::~FunDelegate() +{ + Clear(); +} + +template +inline void std::FunDelegate::Bind(typename DelegateInterface::StaticDelegate::FunT funPtr) +{ + Clear(); + dlgtPtr = std::make_unique >(funPtr); +} + +template +template +inline void std::FunDelegate::Bind(ClassT* obj, typename DelegateInterface::DynamicDelegate::FunT funPtr) +{ + Clear(); + dlgtPtr = std::make_unique >(obj, funPtr); +} + +template +inline ReturnT std::FunDelegate::Invoke(ArgsT ...args) +{ + if (dlgtPtr.get()) + return (*dlgtPtr)(args...); + + return ReturnT(); +} + +template +inline ReturnT std::FunDelegate::operator()(ArgsT ...args) +{ + if (dlgtPtr.get()) + return (*dlgtPtr)(args...); + + return ReturnT(); +} + +template +inline void std::FunDelegate::Clear() +{ + dlgtPtr.reset(); +} + +template +inline std::MultiDelegate::MultiDelegate() +{ + +} + +template +inline std::MultiDelegate::~MultiDelegate() +{ + Clear(); +} + +template +inline void std::MultiDelegate::AddFunc(typename DelegateInterface::StaticDelegate::FunT funPtr) +{ + dlgtPtrArray.push_back(std::make_shared >(funPtr)); +} + +template +template +inline void std::MultiDelegate::AddFunc(ClassT* obj, typename DelegateInterface::DynamicDelegate::FunT funPtr) +{ + dlgtPtrArray.push_back(std::make_shared >(obj, funPtr)); +} + +template +inline void std::MultiDelegate::BroadCast(ArgsT... args) +{ + for (auto it = dlgtPtrArray.begin(); it != dlgtPtrArray.end(); it++) + { + (**it)(args...); + } +} + +template +inline void std::MultiDelegate::operator()(ArgsT ...args) +{ + for (auto it = dlgtPtrArray.begin(); it != dlgtPtrArray.end(); it++) + { + (**it)(args...); + } +} + +template +inline bool std::MultiDelegate::RemoveFunc(typename DelegateInterface::StaticDelegate::FunT funPtr) +{ + for (auto it = dlgtPtrArray.begin(); it != dlgtPtrArray.end(); it++) + { + DelegateInterface::IDelegate* dlgtPtr = (*it).get(); + auto flag = dynamic_cast*>(dlgtPtr); + if (flag && flag->func == funPtr) + { + dlgtPtrArray.erase(it); + return true; + } + } + return false; +} + +template +template +inline bool std::MultiDelegate::RemoveFunc(ClassT* obj, typename DelegateInterface::DynamicDelegate::FunT funPtr) +{ + for (auto it = dlgtPtrArray.begin(); it != dlgtPtrArray.end(); it++) + { + DelegateInterface::IDelegate* dlgtPtr = (*it).get(); + auto flag = dynamic_cast*>(dlgtPtr); + if (flag && flag->func == funPtr && flag->obj == obj) + { + dlgtPtrArray.erase(it); + return true; + } + } + return false; +} + +template +inline void std::MultiDelegate::Clear() +{ + //üΪ0ʱԶͷŶ + dlgtPtrArray.clear(); +} + +#endif \ No newline at end of file diff --git a/src/zplus/src/ZTool/log.cpp b/src/zplus/src/ZTool/log.cpp new file mode 100644 index 0000000..1088673 --- /dev/null +++ b/src/zplus/src/ZTool/log.cpp @@ -0,0 +1,2 @@ +#include "log.h" +LogSystem gLog; \ No newline at end of file diff --git a/src/zplus/src/ZTool/log.h b/src/zplus/src/ZTool/log.h new file mode 100644 index 0000000..120de00 --- /dev/null +++ b/src/zplus/src/ZTool/log.h @@ -0,0 +1,19 @@ +#include "log/log_system.h" +extern LogSystem gLog; + +template +void* FPTR(F f) { + return (void*)f; +} +#define LOG_HELPER(LOG_LEVEL, ...) \ + gLog.log(LOG_LEVEL, "[" + std::string(__FUNCTION__) + "] " + __VA_ARGS__); + +#define LOG_DEBUG(...) LOG_HELPER(LogSystem::LogLevel::debug, __VA_ARGS__); + +#define LOG_INFO(...) LOG_HELPER(LogSystem::LogLevel::info, __VA_ARGS__); + +#define LOG_WARN(...) LOG_HELPER(LogSystem::LogLevel::warn, __VA_ARGS__); + +#define LOG_ERROR(...) LOG_HELPER(LogSystem::LogLevel::error, __VA_ARGS__); + +#define LOG_FATAL(...) LOG_HELPER(LogSystem::LogLevel::fatal, __VA_ARGS__); \ No newline at end of file diff --git a/src/zplus/src/zplus.cpp b/src/zplus/src/zplus.cpp new file mode 100644 index 0000000..f462fa9 --- /dev/null +++ b/src/zplus/src/zplus.cpp @@ -0,0 +1,9 @@ + +#include "ZGrammar/Grammar.h" +#include "ZGrammar/Class.h" +using namespace std; +int main() +{ + TestClass(); + return 0; +} \ No newline at end of file diff --git a/src/zplus/xmake.lua b/src/zplus/xmake.lua new file mode 100644 index 0000000..864cf61 --- /dev/null +++ b/src/zplus/xmake.lua @@ -0,0 +1,7 @@ + +target("zplus") + add_deps("zcore") + set_kind("binary") + add_includedirs("src", {public = true}) + add_files("src/*.cpp","src/**/*.cpp") + add_headerfiles("src/*.h","src/**/*.h") \ No newline at end of file diff --git a/thridpart/lua-protobuf/xmake.lua b/thridpart/lua-protobuf/xmake.lua new file mode 100644 index 0000000..4e5a5cc --- /dev/null +++ b/thridpart/lua-protobuf/xmake.lua @@ -0,0 +1,17 @@ +local lua_xmake = [[ +local kind = "%s" +add_requires("lua") +target("lua-protobuf") + set_kind(kind) + add_packages("lua") + add_files("*.c") + add_headerfiles("*.h") +]] +package("lua-protobuf") + set_urls("https://github.com/starwing/lua-protobuf.git") + add_includedirs("include") + on_install("macosx", "linux", "windows", function (package) + io.writefile("xmake.lua", format(lua_xmake,"static")) + local configs = {kind = "static"} + import("package.tools.xmake").install(package, configs) + end) \ No newline at end of file diff --git a/thridpart/luasocket/package.lua b/thridpart/luasocket/package.lua new file mode 100644 index 0000000..0a57ec3 --- /dev/null +++ b/thridpart/luasocket/package.lua @@ -0,0 +1,11 @@ +package("luasocket") + set_kind("share") + set_urls("https://github.com/lunarmodules/luasocket.git") + on_install("macosx", "linux", "windows", function (package) + print("on_install luasocket", os.tmpfile()) + local configs = {"-DCMAKE_CXX_STANDARD=17"} + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) + table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) + import("package.tools.make").build(package) + import("package.tools.make").make(package, {"install_sw"}) + end) \ No newline at end of file diff --git a/thridpart/luasocket/xmake.lua b/thridpart/luasocket/xmake.lua new file mode 100644 index 0000000..1d0cc0d --- /dev/null +++ b/thridpart/luasocket/xmake.lua @@ -0,0 +1,24 @@ +local lua_xmake = [[ +local kind = "%s" +add_requires("lua") +target("luasocket") + set_basename("core") + set_kind(kind) + add_packages("lua") + add_syslinks("ws2_32") + + + + add_files("src/auxiliar.c","src/buffer.c","src/compat.c" ,"src/except.c" ,"src/inet.c") + add_files("src/io.c","src/luasocket.c","src/options.c" ,"src/select.c" ,"src/tcp.c") + add_files("src/timeout.c","src/udp.c","src/wsocket.c") + add_headerfiles("src/*.h") +]] +package("luasocket") + set_urls("https://github.com/lunarmodules/luasocket.git") + add_includedirs("include") + on_install("macosx", "linux", "windows", function (package) + io.writefile("xmake.lua", format(lua_xmake,"shared")) + local configs = {kind = "shared"} + import("package.tools.xmake").install(package, configs) + end) \ No newline at end of file diff --git a/thridpart/xmake.lua b/thridpart/xmake.lua new file mode 100644 index 0000000..797c654 --- /dev/null +++ b/thridpart/xmake.lua @@ -0,0 +1,3 @@ + +add_requires("spdlog") +includes("**/xmake.lua") \ No newline at end of file diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..076911c --- /dev/null +++ b/xmake.lua @@ -0,0 +1,8 @@ +add_rules("mode.debug", "mode.release") +set_arch("x64") + +set_project("zlib") +includes("thridpart/xmake.lua") +includes("src") +--xmake f -c +--xmake project -k vsxmake2022 -m "debug;release" \ No newline at end of file