lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Egor Skriptunoff <egor.skriptunoff@gmail.com>于2016年11月25日周五 上午5:49写道:
On Thu, Nov 24, 2016 at 7:29 PM, 云风 Cloud Wu <cloudwu@gmail.com> wrote:
I wrote a small tool to reload lua modules online. ( https://github.com/cloudwu/luareload )

It can load lua modules already loaded before, and replace all the old functions in VM with new version.

Interesting.
Are you trying to reload arbitrary Lua module on-the-fly without that module being aware of your attempts?

It has some limit. I create a sandbox to try to load the module first, if any ambiguity is found, it will raise an error and drop the sandbox.

And you can not call or write anything out of module during the require stage (If you do , the reload will raise an error, too), 
but refer the variable out of sandbox is allowed. For example : 

 local othermod = require "othermod"  -- Is allowed
 local something = othermod.something  -- Is allowed
 othermod.something = 1 -- Raise an error
 GLOBAL = 1  -- Raise an error
 local tinsert = table.insert  -- Is allowed
 table.insert({}, 1)  -- Raise an error

And it will merge the same tables in the module are both in old and new version. Reloading would not remove object not exist in the new version.