还在读..
字节流读取
function Test()
local file = io.open("path/file.bytes", "rb")
local content = file:read("*all")
local offset = 1
local length
length, offset = GetInt(content, offset)
for i = 1, length do
name, offset = _GetString(content, offset)
print("名:" .. name)
dataLength, offset = _GetInt(content, offset)
print("data长度:" .. dataLength)
for i = 1, dataLengthdo
IntX, offset = _GetInt(content, offset)
IntY, offset = _GetInt(content, offset)
IntZ, offset = _GetInt(content, offset)
end
end
end
function _GetString(content, offset)
local value = ""
local length = string.byte(content, offset)
offset = offset + 1
for j = 1, length do
value = value .. string.char(string.byte(content, offset))
offset = offset + 1
end
return value, offset
end
function _GetInt(content, offset)
local value = string.byte(content, offset + 0) +
string.byte(content, offset + 1) * 256 +
string.byte(content, offset + 2) * 256 * 256 +
string.byte(content, offset + 3) * 256 * 256 * 256
value = (value > 2147483647) and (value - 4294967296) or value
offset = offset + 4
return value, offset
end
string操作
XLua
1.XLua使用XluaCustomExport添加胶水代码
2. .与:
xx.xx(self, p1) 等价于 function xx:xx(p1)
3.Xlua C#侧与lua侧的类型映射关系
C#与Lua
X3Lua.DoString("SkillCfgTool = require('EditorTools.Battle.SkillCfgTool')");
LuaFunction luafunction = X3Lua.GetLuaFunction("SkillCfgTool.GetSkillCfgByTLName");
if (luafunction != null)
{
var vals = luafunction.Call(eventConfig.Key);
LuaTable table = vals[0] as LuaTable;
int arrayLength = table.Length;
Debug.LogError("arrayLength" + arrayLength);
for (int i = 1; i < arrayLength; i++)
{
if (string.IsNullOrEmpty(cfgID))
cfgID = table.Get<int, string>(i);
else
{
cfgID += ", " + table.Get<int, string>(i);
Debug.LogError("第二个" + cfgID);
}
}
}
调试lua
local function AttachDebugger()
package.cpath = package.cpath .. ';C:/Users/userName/AppData/Roaming/JetBrains/IntelliJIdea2020.3/plugins/intellij-emmylua/classes/debugger/emmy/windows/x64/?.dll'
local dbg = require('emmy_core')
dbg.tcpConnect('localhost', 9966)
end
pcall(AttachDebugger)
Lua程序设计
测试用 菜鸟教程在线编辑器
进度 35页
- lua加载一个程序块
- lua读取一个输入数字
- lua数字
卧槽 是这样的吗
→问了大佬
①精度问题还是有 做了测试也的确如此
②精度问题是因为cpu的架构不一样 同cpu架构结果应该是一样
③不知道和上面的浮点数4舍5入有什么关系 - Lua字符串
额外学了个Find所有local str = "E(EEEEE(E Fint235234" local upStr = string.upper(str) local index while(true) do index = string.find(upStr,'FINT',index) if index == nil then --condition = false print("退出了") break else local tarStr = string.sub(str, index, index+3) print("发现了" .. (index) .. tarStr) index = index +1 end end
- Lua Table
GC
语法糖
select
local table = {select(...,1)} 返回1开始的table
local a,b,c = select(...,1) 返回1开始的参数分别给到a,b,c
- 循环