Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a way to reload lua scripts during run-time?

Tags:

scripting

lua

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?

like image 669
zooropa Avatar asked May 11 '10 15:05

zooropa


1 Answers

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.

like image 187
Doug Currie Avatar answered Oct 24 '22 00:10

Doug Currie