Lua热更新时正确设置文件名

(金庆的专栏 2016.12)

Lua热更新模块见:
https://github.com/jinq0123/hotfix

其中使用 load(chunk) 来加载更新后的内容,发现 traceback 打印缺少文件名,
这对于调试纠错有不小的影响。

test.lua

local M = {}

function M.test()
  assert(false, "test assert 5")
end

return M

如下测试:

D:\Jinq\temp\lua>d:\Jinq\tools\lua-5.3.2_Win64_bin\lua53
Lua 5.3.2  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> hf = require("hotfix")
> t = require("test")
> t.test()
.\test.lua:4: test assert
stack traceback:
        [C]: in function 'assert'
        .\test.lua:4: in function 'test.test'
        (...tail calls...)
        [C]: in ?
> hf.hotfix_module("test")
table: 000000000078a6d0
> t.test()
[string "local M = {}..."]:4: test assert 2
stack traceback:
        [C]: in function 'assert'
        [string "local M = {}..."]:4: in function 'test.test'
        (...tail calls...)
        [C]: in ?
>

文件名信息被文件内容字符串给代替了。

改成:load(chunk, file_path), 结果是这样的:

> t.test()
[string ".\test.lua"]:4: test assert 3
stack traceback:
        [C]: in function 'assert'
        [string ".\test.lua"]:4: in function 'test.test'
        (...tail calls...)
        [C]: in ?
>

查看源码,发现需要用"@"前缀来表示这是个文件名,于是改成:

    load(chunk, '@'..file_path)
    
终于正常了。

Lua热更新时正确设置文件名的更多相关文章

  1. Lua热更新(hotfix)

    Lua热更新(hotfix)(金庆的专栏)hotfixLua 5.2/5.3 hotfix. Hot update functions and keep old data.https://github ...

  2. (原创)cocos lua 热更新从零开始(一)最简单demo

    开发环境:WIN7 + cocos2dx 3.10 lua版本 0.学习这篇内容的基础是你要会创建并运行一个cocos lua项目 1.热更新的思想所谓的热更新,就是在线更新代码和资源.热更新的过程首 ...

  3. 出售一套Unity + Lua热更新框架代码

    出售一套Unity + Lua的客户端框架代码,功能有资源管理.网络通信.配置文件解析.热更新.文件读写.Lua加密揭秘.UI框架.打包工具.编辑器工具等,已经在多个实际项目(已上线)中使用.代码优雅 ...

  4. [Erlang10]为什么热更新时,Shell执行2次l(Module)后会把原来用到Module的进程 kill?

    0. 问题引入: -module(hot_code_server). -compile(export_all). start() –> erlang:register(?MODULE, erla ...

  5. 使用bugly热更新时自定义升级弹窗的UI样式

    项目的热更新用的bugly,不过一直都只是使用他自带的升级弹窗. 不过UI小姐姐说弹窗太丑了,要自定义. bugly有提供自定义UI的官方文档:https://bugly.qq.com/docs/us ...

  6. cocos2dx lua 热更新方案的实现

    (Upgrade.h) #include <stdio.h> #include "cocos2d.h" #include "framework/utils/U ...

  7. 腾讯开源手游热更新方案,Unity3D下的Lua编程

    原文:http://www.sohu.com/a/123334175_355140 作者|车雄生 编辑|木环 腾讯最近在开源方面的动作不断:先是微信跨平台基础组件Mars宣布开源,腾讯手游又于近期开源 ...

  8. Unity热更新 xLua

    xLua是Unity3D下Lua编程解决方案,自2016年初推广以来,已经应用于十多款腾讯自研游戏,因其良好性能.易用性.扩展性而广受好评.现在,腾讯已经将xLua开源到GitHub. 2016年12 ...

  9. 深入理解xLua热更新原理

    热更新简介 热更新是指在不需要重新编译打包游戏的情况下,在线更新游戏中的一些非核心代码和资源,比如活动运营和打补丁.热更新分为资源热更新和代码热更新两种,代码热更新实际上也是把代码当成资源的一种热更新 ...

随机推荐

  1. hive:创建索引

    hive也是支持索引的使用,但是如果表中已经有数据的情况下,创建索引的过程不是特别快. 已经拥有表: create table if not exists llcfpd_withgroupbykey( ...

  2. Java-NIO(一):简介

    Java NIO简介: Java New IO Non Blocking IO,从java1.4版本就开始引入了新的IO API,可以替代标准的Java IO API.NIO与原来的IO有同样的作用和 ...

  3. 扩展第二屏幕发生Out Of Range及扩展后耳机没声音解决方案

    新年好\(^o^)/~ 拓展屏幕这种事情.其实很简单的.无非就分辨率跟刷新频率.有时候一接好就可以了.有时候怎么也弄不出来.我也是搞了蛮久.昨天突然弄通了.小记一下说不定能帮到同需求人. [设备] 主 ...

  4. [LeetCode] Best Time to Buy and Sell Stock with Transaction Fee 买股票的最佳时间含交易费

    Your are given an array of integers prices, for which the i-th element is the price of a given stock ...

  5. [LeetCode] Convert BST to Greater Tree 将二叉搜索树BST转为较大树

    Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original B ...

  6. 2018.4.16Spring.Net入门学习内容

    三大方面: IoC:Inversion of Control 控制翻转:就是创建对象的权利由开发人员自己控制New,转到了由容器来控制. DI:Dependency InjectionIt is a ...

  7. enumerate给列表加序号

    #coding=utf-8#给列表加上序号,enumerate(l1),默认从0开始l1=['money','house','joo']for item in enumerate(l1,1): #pr ...

  8. js获取设备

    总结了一个JavaScript获取当前终端类型(pc, mobile),操作系统类型,浏览器类型,浏览器版本的小工具. 个人觉得还行,测试过没有问题,能识别ie7以及以上. 1 2 3 4 5 6 7 ...

  9. [UOJ] #217. 【UNR #1】奇怪的线段树

    题解见大佬博客 我的丑陋代码: #include<cstdio> #include<cstring> #include<cstdlib> inline int re ...

  10. Codeforces Round #460 D. Karen and Cards

    Description Karen just got home from the supermarket, and is getting ready to go to sleep. After tak ...