upload xmake project

This commit is contained in:
ouczbs 2023-07-05 09:24:50 +08:00
commit b2635c074a
72 changed files with 2335 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
.vs/
.vscode/.cache/
.vscode/compile_commands.json
.xmake/
build/
vsxmake*/

67
.vscode/settings.json vendored Normal file
View File

@ -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"
}

22
.vscode/sftp.json vendored Normal file
View File

@ -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/**"
]
}

46
src/clua/xmake.lua Normal file
View File

@ -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"})

4
src/xmake.lua Normal file
View File

@ -0,0 +1,4 @@
add_requires("lua","luasocket")
add_requires("protobuf-cpp","lua-protobuf")
includes("*/xmake.lua")

View File

@ -0,0 +1,30 @@
#include "log_system.h"
#include <spdlog/async.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
LogSystem::LogSystem()
{
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
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<spdlog::async_logger>("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();
}

View File

@ -0,0 +1,59 @@
#pragma once
#include "spdlog/spdlog.h"
#include <cstdint>
#include <stdexcept>
class LogSystem final
{
public:
enum class LogLevel : uint8_t
{
debug,
info,
warn,
error,
fatal
};
public:
LogSystem();
~LogSystem();
template<typename... TARGS>
void log(LogLevel level, TARGS&&... args)
{
switch (level)
{
case LogLevel::debug:
m_logger->debug(std::forward<TARGS>(args)...);
break;
case LogLevel::info:
m_logger->info(std::forward<TARGS>(args)...);
break;
case LogLevel::warn:
m_logger->warn(std::forward<TARGS>(args)...);
break;
case LogLevel::error:
m_logger->error(std::forward<TARGS>(args)...);
break;
case LogLevel::fatal:
m_logger->critical(std::forward<TARGS>(args)...);
fatalCallback(std::forward<TARGS>(args)...);
break;
default:
break;
}
}
template<typename... TARGS>
void fatalCallback(TARGS&&... args)
{
const std::string format_str = fmt::format(std::forward<TARGS>(args)...);
throw std::runtime_error(format_str);
}
private:
std::shared_ptr<spdlog::logger> m_logger;
};

77
src/zcore/xmake.lua Normal file
View File

@ -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
--

76
src/zfile/xmake.lua Normal file
View File

@ -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
--

View File

@ -0,0 +1,5 @@

BP_MMOGameMode MMOGameMode
0
UI_FunBtnEntryGameWorld.UI.Entry.FunBtnEntry

View File

@ -0,0 +1,5 @@

BP_MMOGameMode MMOGameMode
0
UI_FunBtnEntryGameWorld.UI.Entry.FunBtnEntry

54
src/zlua/lua/config.lua Normal file
View File

@ -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

View File

@ -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"

16
src/zlua/lua/testref.lua Normal file
View File

@ -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))

11
src/zlua/proto/Cmd.proto Normal file
View File

@ -0,0 +1,11 @@
syntax = "proto3";
package pb;
option go_package = ".;pb";
enum CMD
{
CMD_INVALID = 0;
xLoginAccountCmd = 1001;
xLoginAccountAckCmd = 1002;
}

View File

@ -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<string, UIItem> 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;
}

View File

@ -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;
}

View File

@ -0,0 +1,10 @@
syntax = "proto3";
package pb;
option go_package = ".;pb";
enum MT
{
MT_INVALID = 0;
GameLogin = 1001;
}

11
src/zlua/proto/Wrap.proto Normal file
View File

@ -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; //
}

21
src/zlua/proto/pb2cpp.bat Normal file
View File

@ -0,0 +1,21 @@
@echo off
setlocal EnableDelayedExpansion
set /p=<nul>exec.bat
set destPath=%2cpp/
ECHO @echo on >>exec.bat
for %%i in (*.proto) do (
set /p="protoc --cpp_out=%destPath% %%i "<nul >> exec.bat
findstr /b /i import %%i >nul
if !errorlevel! equ 0 (set /p="--include_imports "<nul >> exec.bat)
for /f tokens^=2*^ delims^=^" %%a in ('findstr /b /i import %%i') do (
set /p= %%a <nul>> exec.bat
set /a wind+=1
)
ECHO.>> exec.bat
)
ECHO @echo off>> exec.bat
call exec.bat
del exec.bat
::pause

21
src/zlua/proto/pb2pbc.bat Normal file
View File

@ -0,0 +1,21 @@
@echo off
setlocal EnableDelayedExpansion
set /p=<nul>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 "<nul >> exec.bat
findstr /b /i import %%i >nul
if !errorlevel! equ 0 (set /p="--include_imports "<nul >> exec.bat)
for /f tokens^=2*^ delims^=^" %%a in ('findstr /b /i import %%i') do (
set /p= %%a <nul>> exec.bat
set /a wind+=1
)
ECHO.>> exec.bat
)
ECHO @echo off>> exec.bat
call exec.bat
del exec.bat
::pause

20
src/zlua/src/CLua.cpp Normal file
View File

@ -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;
}

View File

@ -0,0 +1,14 @@
#pragma once
//#include "pb.h"
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#include <iostream>
#include <fstream>
#include <string>
namespace clua {
const std::string path_config = "config/";
const std::string lua_config = "lua/";
}

View File

@ -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;
}

View File

@ -0,0 +1,6 @@
#pragma once
#include "base/Degines.h"
class luaapi
{
};

View File

@ -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;
}

View File

@ -0,0 +1,7 @@
#pragma once
#include "base/Degines.h"
int TestLuaRef(lua_State* L);
class luaref
{
};

View File

@ -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;
}
///< ִ<><D6B4>lua<75>ļ<EFBFBD>
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;
}

View File

@ -0,0 +1,7 @@
#pragma once
#include "base/Degines.h"
int TestLuaDebug(lua_State* L);
class luadebug
{
};

View File

@ -0,0 +1,78 @@
#include "protobuf.h"
#include <iostream>
#include <fstream>
#include <string>
//#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;
}
*/

View File

@ -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
{
};

View File

@ -0,0 +1,30 @@
#include "luautil.h"
#include <iostream>
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;
}

View File

@ -0,0 +1,9 @@
#pragma once
#include "base/Degines.h"
int stackDump(lua_State* L);
class luautil
{
};

44
src/zlua/xmake.lua Normal file
View File

@ -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"})

View File

@ -0,0 +1 @@
#pragma once

View File

@ -0,0 +1,3 @@
#pragma once
const uint32 MAX_PATH = 260;

View File

@ -0,0 +1,22 @@
#pragma once
#include <assert.h>
#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

View File

@ -0,0 +1,6 @@
#pragma once
#include "Define.h"
#include "Type.h"
#include "Inline.h"
#include "Const.h"
#include "Config.h"

View File

@ -0,0 +1 @@
#pragma once

View File

@ -0,0 +1,7 @@
#pragma once
typedef __int64 int64;
typedef __int32 int32;
typedef unsigned char byte;
typedef unsigned __int32 uint32;
typedef unsigned __int64 uint64;

View File

@ -0,0 +1,87 @@
#pragma once
#include <iostream>
#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();
}

View File

@ -0,0 +1,14 @@
#pragma once
#include "Template .h"
#include "Parameter.h"
#include "Class.h"
#include <iomanip>
using namespace std;
void TestGrammer() {
cout << "\t TestGrammer" << endl;
//TestTemplate();
TestParmeter();
TestClass();
//TestReflex();
}

View File

@ -0,0 +1,95 @@
#pragma once
#include <iostream>
#include <iomanip>
#include <string>
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 <typename ...TArgs>
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");
}

View File

@ -0,0 +1,41 @@
#pragma once
#pragma once
#include <iostream>
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;
}

View File

@ -0,0 +1,45 @@
#pragma once
#include <iostream>
#include <typeinfo>
using namespace std;
template <class Type> class Test {
public:
void f() {
cout << "My Type is: " << typeid(*this).name() << endl;
}
};
template <typename T>
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<void*>(FPii) << endl;
cout << reinterpret_cast<void*>(FPff) << endl;
}
void Template1() {
Test<char>().f();
Test<int>().f();
cout.setf(ios::boolalpha);
cout << bool(typeid(Test<char>) == typeid(Test<int>)) << endl;
}
void TestTemplate() {
cout << "\t\t TestTemplate" << endl;
Template1();
Template2();
}

View File

@ -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;
}
}
};

View File

@ -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);
}
};

View File

@ -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);
}
};

View File

@ -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);
}
};

View File

@ -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;
}
}
};

View File

@ -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);
}
};

View File

@ -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);
}
};

View File

@ -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);
}
};

View File

@ -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;
}
}
}
}
};

View File

@ -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;
}
}
};

View File

@ -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<iostream>
using namespace std;
template <typename T>
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();
}

View File

@ -0,0 +1,21 @@
#pragma once
#include<iostream>
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;
}

View File

@ -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;
}

View File

@ -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();

View File

@ -0,0 +1,19 @@
#include "TestDelegate.h"
void PrintAdd3(int a, int b)
{
cout << "Call PrintAdd, Value = " << a + b << endl;
}
int TestDelegateMain()
{
/*
vector<TestStruct> 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;
}

View File

@ -0,0 +1,30 @@
#pragma once
#include "ZTool/delegate.h"
#include <iostream>
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();

View File

@ -0,0 +1,31 @@
#pragma once
# include <chrono>
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<milliseconds>(diff).count());
}
return 0;
}
private:
system_clock::time_point m_start;
};

View File

@ -0,0 +1,275 @@
#pragma once
#ifndef DELEGATE_H
#define DELEGATE_H
#include <memory>
#include <vector>
#ifndef DECLARE_FUNCTION_DELEGATE
#define DECLARE_FUNCTION_DELEGATE(DelegateName, ReturnValueType, ...) typedef std::FunDelegate<ReturnValueType, __VA_ARGS__> (DelegateName);
#define DECLARE_FUNCTION_DELEGATE_NO_PARAMETER(DelegateName, ReturnValueType) typedef std::FunDelegate<ReturnValueType> (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<void> (DelegateName);
#endif
namespace std
{
class DelegateInterface final
{
public:
template<typename ReturnT, typename ...ArgsT>
friend class FunDelegate;
template<typename ...ArgsT>
friend class MultiDelegate;
private:
template<typename ReturnT, typename ...ArgsT>
struct IDelegate
{
virtual ReturnT operator() (ArgsT... args) = 0;
virtual ~IDelegate() { };
};
//类成员函数模板
template<typename ClassT, typename ReturnT, typename ...ArgsT>
class DynamicDelegate : public IDelegate<ReturnT, ArgsT...>
{
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;
};
//非成员函数模板
template<typename ReturnT, typename ...ArgsT>
class StaticDelegate : public IDelegate<ReturnT, ArgsT...>
{
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<typename ReturnT, typename ...ArgsT>
class FunDelegate final
{
public:
explicit FunDelegate();
explicit FunDelegate(typename DelegateInterface::StaticDelegate<ReturnT, ArgsT...>::FunT funPtr);
template<typename ClassT>
explicit FunDelegate(ClassT* obj, typename DelegateInterface::DynamicDelegate<ClassT, ReturnT, ArgsT...>::FunT funPtr);
~FunDelegate();
void Bind(typename DelegateInterface::StaticDelegate<ReturnT, ArgsT...>::FunT funPtr);
template<typename ClassT>
void Bind(ClassT* obj, typename DelegateInterface::DynamicDelegate<ClassT, ReturnT, ArgsT...>::FunT funPtr);
ReturnT Invoke(ArgsT... args);
ReturnT operator() (ArgsT... args);
void Clear();
private:
std::unique_ptr<DelegateInterface::IDelegate<ReturnT, ArgsT...> > dlgtPtr;
};
template<typename ...ArgsT>
class MultiDelegate final
{
public:
MultiDelegate();
~MultiDelegate();
void AddFunc(typename DelegateInterface::StaticDelegate<void, ArgsT...>::FunT funPtr);
template<typename ClassT>
void AddFunc(ClassT* obj, typename DelegateInterface::DynamicDelegate<ClassT, void, ArgsT...>::FunT funPtr);
void BroadCast(ArgsT... args);
void operator() (ArgsT... args);
bool RemoveFunc(typename DelegateInterface::StaticDelegate<void, ArgsT...>::FunT funPtr);
template<typename ClassT>
bool RemoveFunc(ClassT* obj, typename DelegateInterface::DynamicDelegate<ClassT, void, ArgsT...>::FunT funPtr);
void Clear();
private:
std::vector<std::shared_ptr<DelegateInterface::IDelegate<void, ArgsT...> > > dlgtPtrArray;
};
}
template<typename ReturnT, typename ...ArgsT>
inline std::FunDelegate<ReturnT, ArgsT...>::FunDelegate()
{
}
template<typename ReturnT, typename ...ArgsT>
inline std::FunDelegate<ReturnT, ArgsT...>::FunDelegate(typename DelegateInterface::StaticDelegate<ReturnT, ArgsT...>::FunT funPtr)
{
Bind(funPtr);
}
template<typename ReturnT, typename ...ArgsT>
template<typename ClassT>
inline std::FunDelegate<ReturnT, ArgsT...>::FunDelegate(ClassT* obj, typename DelegateInterface::DynamicDelegate<ClassT, ReturnT, ArgsT...>::FunT funPtr)
{
Bind(obj, funPtr);
}
template<typename ReturnT, typename ...ArgsT>
inline std::FunDelegate<ReturnT, ArgsT...>::~FunDelegate()
{
Clear();
}
template<typename ReturnT, typename ...ArgsT>
inline void std::FunDelegate<ReturnT, ArgsT...>::Bind(typename DelegateInterface::StaticDelegate<ReturnT, ArgsT...>::FunT funPtr)
{
Clear();
dlgtPtr = std::make_unique<DelegateInterface::StaticDelegate<ReturnT, ArgsT...> >(funPtr);
}
template<typename ReturnT, typename ...ArgsT>
template<typename ClassT>
inline void std::FunDelegate<ReturnT, ArgsT...>::Bind(ClassT* obj, typename DelegateInterface::DynamicDelegate<ClassT, ReturnT, ArgsT...>::FunT funPtr)
{
Clear();
dlgtPtr = std::make_unique<DelegateInterface::DynamicDelegate<ClassT, ReturnT, ArgsT...> >(obj, funPtr);
}
template<typename ReturnT, typename ...ArgsT>
inline ReturnT std::FunDelegate<ReturnT, ArgsT...>::Invoke(ArgsT ...args)
{
if (dlgtPtr.get())
return (*dlgtPtr)(args...);
return ReturnT();
}
template<typename ReturnT, typename ...ArgsT>
inline ReturnT std::FunDelegate<ReturnT, ArgsT...>::operator()(ArgsT ...args)
{
if (dlgtPtr.get())
return (*dlgtPtr)(args...);
return ReturnT();
}
template<typename ReturnT, typename ...ArgsT>
inline void std::FunDelegate<ReturnT, ArgsT...>::Clear()
{
dlgtPtr.reset();
}
template<typename ...ArgsT>
inline std::MultiDelegate<ArgsT...>::MultiDelegate()
{
}
template<typename ...ArgsT>
inline std::MultiDelegate<ArgsT...>::~MultiDelegate()
{
Clear();
}
template<typename ...ArgsT>
inline void std::MultiDelegate<ArgsT...>::AddFunc(typename DelegateInterface::StaticDelegate<void, ArgsT...>::FunT funPtr)
{
dlgtPtrArray.push_back(std::make_shared<DelegateInterface::StaticDelegate<void, ArgsT...> >(funPtr));
}
template<typename ...ArgsT>
template<typename ClassT>
inline void std::MultiDelegate<ArgsT...>::AddFunc(ClassT* obj, typename DelegateInterface::DynamicDelegate<ClassT, void, ArgsT...>::FunT funPtr)
{
dlgtPtrArray.push_back(std::make_shared<DelegateInterface::DynamicDelegate<ClassT, void, ArgsT...> >(obj, funPtr));
}
template<typename ...ArgsT>
inline void std::MultiDelegate<ArgsT...>::BroadCast(ArgsT... args)
{
for (auto it = dlgtPtrArray.begin(); it != dlgtPtrArray.end(); it++)
{
(**it)(args...);
}
}
template<typename ...ArgsT>
inline void std::MultiDelegate<ArgsT...>::operator()(ArgsT ...args)
{
for (auto it = dlgtPtrArray.begin(); it != dlgtPtrArray.end(); it++)
{
(**it)(args...);
}
}
template<typename ...ArgsT>
inline bool std::MultiDelegate<ArgsT...>::RemoveFunc(typename DelegateInterface::StaticDelegate<void, ArgsT...>::FunT funPtr)
{
for (auto it = dlgtPtrArray.begin(); it != dlgtPtrArray.end(); it++)
{
DelegateInterface::IDelegate<void, ArgsT...>* dlgtPtr = (*it).get();
auto flag = dynamic_cast<DelegateInterface::StaticDelegate<void, ArgsT...>*>(dlgtPtr);
if (flag && flag->func == funPtr)
{
dlgtPtrArray.erase(it);
return true;
}
}
return false;
}
template<typename ...ArgsT>
template<typename ClassT>
inline bool std::MultiDelegate<ArgsT...>::RemoveFunc(ClassT* obj, typename DelegateInterface::DynamicDelegate<ClassT, void, ArgsT...>::FunT funPtr)
{
for (auto it = dlgtPtrArray.begin(); it != dlgtPtrArray.end(); it++)
{
DelegateInterface::IDelegate<void, ArgsT...>* dlgtPtr = (*it).get();
auto flag = dynamic_cast<DelegateInterface::DynamicDelegate<ClassT, void, ArgsT...>*>(dlgtPtr);
if (flag && flag->func == funPtr && flag->obj == obj)
{
dlgtPtrArray.erase(it);
return true;
}
}
return false;
}
template<typename ...ArgsT>
inline void std::MultiDelegate<ArgsT...>::Clear()
{
//引用计数为0时自动释放对象
dlgtPtrArray.clear();
}
#endif

View File

@ -0,0 +1,2 @@
#include "log.h"
LogSystem gLog;

19
src/zplus/src/ZTool/log.h Normal file
View File

@ -0,0 +1,19 @@
#include "log/log_system.h"
extern LogSystem gLog;
template<typename F>
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__);

9
src/zplus/src/zplus.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "ZGrammar/Grammar.h"
#include "ZGrammar/Class.h"
using namespace std;
int main()
{
TestClass();
return 0;
}

7
src/zplus/xmake.lua Normal file
View File

@ -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")

View File

@ -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)

View File

@ -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)

View File

@ -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)

3
thridpart/xmake.lua Normal file
View File

@ -0,0 +1,3 @@
add_requires("spdlog")
includes("**/xmake.lua")

8
xmake.lua Normal file
View File

@ -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"