sniper00 / moon Goto Github PK
View Code? Open in Web Editor NEWA lightweight game server framework implemented with Actor Model
License: MIT License
A lightweight game server framework implemented with Actor Model
License: MIT License
编写逻辑时很容易用到table
key
为1
起始的lua
table
, 如果写出下面代码
json.options('enable_sparse_array', true)
local t = {}
t[1] = "111"
t[2] = "222"
t[3] = "333"
t[4] = "444"
t[3] = nil
local str = json.encode(t)
print(str)
print_r(json.decode(str))
对于 json 中的 null 会使用 json.null
lua lightuserdata
表示:
encode: ["111","222",null,"444"]
decode: {
[1] = "111",
[2] = "222",
[3] = userdata: 0000000000000000,
[4] = "444",
}
这样在编写lua逻辑时判断元素是否存在时会比较麻烦,需要多一层对json.null
的判断。
对于lua 大多数情况下并不关系数据是array还是object, 为了简化,现在提供了选项 json options
enable_sparse_array
, 这个选项是默认为false。效果如下:
encode: {"1":"111","2":"222","4":"444"}
decode: {
[1] = "111",
[2] = "222",
[4] = "444",
}
注意,如果要对接其它语言,需要区分array
和object
时, 按object操作方式的table 不建议定义 key=1的元素
使用httpc.get访问https接口,看表现是会用http访问。
作者您好!
非常钦佩您的这个工程,我在学习中。
有个问题就是:我看到其中不少lua代码,我用visual studio 2019 无法进入lua中调试,不知道您有什么好的建议?
我是个C++程序员。
gcc version 13.2.1 20230801 (GCC)
In file included from ../../../moon-src/core/worker.h:4,
from ../../../moon-src/core/server.h:6,
from ../../../lualib-src/lua_moon.cpp:8:
../../../moon-src/core/network/socket.h:95:18: error: declaration of ‘uint32_t moon::socket_server::udp(uint32_t, std::string_view, uint16_t)’ changes meaning of ‘udp’ [-Wchanges-meaning]
95 | uint32_t udp(uint32_t owner, std::string_view host, uint16_t port);
| ^~~
../../../moon-src/core/network/socket.h:77:13: note: used here to mean ‘class asio::ip::udp’
77 | udp::endpoint from_ep;
| ^~~
In file included from ../../../third/asio.hpp:143,
from ../../../moon-src/core/network/socket.h:4:
../../../third/asio/ip/udp.hpp:42:7: note: declared here
42 | class udp
| ^~~
list.lua queue.size(q) 获得队列的大小为什么不是 q.t -q.h +1 ? queue.push的时候是t+1, pop的时候是h + 1.
coord_transform(hitPos);
电脑上只安装了VS2015,不想折腾VS2022这个体积巨大的东西了
作者你好,线上环境是windows server,moon也能部署在windows server吧?还是说windows上仅仅是调试开发?
Lua table经过json encode后,整型key会被编码成字符串,造成decode后只根据json数据类型无法还原整型key,现在想到一个方案: lua变量不能是 -
,0-9
开头, json key decode时,先检测第一个字符是否是-
,0-9
开头,如果是,就说明这是一个整型key。
这种方案有一些限制
-
,0-9
开头的非纯数字字符串做keymoon/moon-src/luabind/lua_json.cpp
Line 267 in 9072cec
moon.new_service这个api是怎么获得服务id并返回的?
看了好久也没有捋清楚. math.tointeger(co_yield()) 不是应该挂起当前协程么?
我写了个例子, 我理解的是moon.new_service 执行完都需要再次执行coroutine.resume才能把for循环跑完. 因为new_service最后yield的了? 但是实际是for循环是一次都执行完了,并没有中途挂起, 而且返回了服务id. 一直也没有看懂这服务id怎么来的.
求帮忙讲解一下.
moon.async(function()
local conf = {
base_name = "gate",
file = "service_gate.lua",
host = "0.0.0.0",
base_port = 20520,
num = 5,
unique = true, -- 通过name做唯一区分,name不能相同
}
for i = 1, conf.num do
conf.port = conf.base_port + i - 1
conf.name = conf.base_name .. i
local r = moon.new_service("lua", conf)
end
end)
BUILDVCTOOLS: C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
Microsoft Visual Studio 2022 版本 17.6.4.
版权所有(C) Microsoft Corp.。保留所有权利。
已启动重新生成...
1>------ 已启动全部重新生成: 项目: sharetable, 配置: Release x64 ------
2>------ 已启动全部重新生成: 项目: pb, 配置: Release x64 ------
3>------ 已启动全部重新生成: 项目: mongo, 配置: Release x64 ------
4>------ 已启动全部重新生成: 项目: mimalloc, 配置: Release x64 ------
5>------ 已启动全部重新生成: 项目: lualib, 配置: Release x64 ------
6>------ 已启动全部重新生成: 项目: lua, 配置: Release x64 ------
7>------ 已启动全部重新生成: 项目: crypt, 配置: Release x64 ------
1>lua-sharetable.c
2>pb.c
3>lua-bson.c
1>sharetable.vcxproj -> G:\unityProj\2D\KnightsLike\Moon\moon-master\build\bin\Release\sharetable.lib
4>static.c
4>c1 : fatal error C1083: 无法打开源文件: “......\third\mimalloc\src\static.c”: No such file or directory
4>已完成生成项目“mimalloc.vcxproj”的操作 - 失败。
原因:
VS2022的bug, 存在多个版本VCToolsversion时, 不会默认使用最新版
具体可见这个目录存在多个版本:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC
解决方案:
删除这个目录下 C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build 这两个文件
Microsoft.VCToolsVersion.v143.default.props
Microsoft.VCToolsVersion.v143.default.txt
参考资料:
actions/runner-images#9670
https://developercommunity.visualstudio.com/t/Latest-Visual-Studio-version-1791-ca/10598722#T-N10605771
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.