lua调用

一、文件读存:
-- 似乎不支持大文件(不能超过9k?)
function FileSaveLoad()
      local file = io.open("c:\\in.lua", "r");
      assert(file);
      local data = file:read("*a"); -- 读取所有内容
      file:close();
      file = io.open("c:\\out.lua", "w");
      assert(file);
      file:write(data);
      file:close();
end
FileSaveLoad();

二、非循环表格处理:



HERO = 1;
MONSTER = 2;
BUILDING = 3;
SUMUNIT = 4;
cha = {};
cha[1] = 
{
      basic = 
      {
      Name = "农民",    --NPC名字
      cha_type = HERO,  --NPC模型
      },
      combat = 
      {
       acquire = 600.00,  --主动攻击范围
       basic_def = 10,   --基础防御
      },
};

function SaveTableContent(file, obj)
      local szType = type(obj);
      print(szType);
      if szType == "number" then
            file:write(obj);
      elseif szType == "string" then
            file:write(string.format("%q", obj));
      elseif szType == "table" then
            --把table的内容格式化写入文件
            file:write("{\n");
            for i, v in pairs(obj) do
                  file:write("[");
                  SaveTableContent(file, i);
                  file:write("]=\n");
                  SaveTableContent(file, v);
                  file:write(", \n");
             end
            file:write("}\n");
      else
      error("can't serialize a "..szType);
      end
end

function SaveTable()
      local file = io.open("e:\\00_00_00_海外组_学习\\写入.txt", "w");
      assert(file);
      file:write("cha = {}\n");
      file:write("cha[1] = \n");
      SaveTableContent(file, cha[1]);
      file:write("}\n");
      file:close();
end

SaveTable();

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值