tags:

views:

75

answers:

1

I want to reload lua scripts at run-time. What are the ways to do this? Do you just have to reinitialize the lua system and then re-read all the lua files?

+6  A: 

If (a) the Lua scripts are in modules, and (b) the modules don't affect globals or tables outside the scope of the module, you can use package.loaded.????? = nil to cause require to reload the module:

> require "lsqlite3"
> =sqlite3.version
function: 0x10010df50
> sqlite3.version = "33"
> return sqlite3.version
33
> require "lsqlite3"
> return sqlite3.version
33
> package.loaded.lsqlite3 = nil
> return sqlite3.version
33
> require "lsqlite3"
> return sqlite3.version
function: 0x10010c2a0
> 

Similarly, if the non-module scripts are well behaved in that they (a) only define a single table, and (b) don't affect globals or other tables, then simply reloading the script will work as well.

Doug Currie