【读书笔记】《Lua程序设计》

还在读..

 

字节流读取

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页

  1. lua加载一个程序块


     
  2. lua读取一个输入数字
     


     
  3. lua数字

    卧槽  是这样的吗
    →问了大佬
    ①精度问题还是有 做了测试也的确如此
    ②精度问题是因为cpu的架构不一样 同cpu架构结果应该是一样
    ③不知道和上面的浮点数4舍5入有什么关系

  4. 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
  5. Lua Table

    GC

    语法糖


    select
    local table = {select(...,1)} 返回1开始的table
    local a,b,c = select(...,1) 返回1开始的参数分别给到a,b,c
     
  6. 循环



  7.  

  8.  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值