This module is used to track the requires in loaded Lua scripts.
The purpose of this functionality is it to enable the loading of all Lua scripts on a single process and broadcasting them to all others, without the need to access the files by all processes.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character, | private, | parameter | :: | nl | = | C_NEW_LINE | |
character(len=1300), | private, | parameter | :: | track_rq_Lua | = | "track_rq = {}"//nl//"track_rq.nesting = 0"//nl//"track_rq.code = {}"//nl//"track_rq.open_files = {}"//nl//"track_rq.open_files.count = 0"//nl//"track_rq.open_files.name = {}"//nl//"track_rq.open_files.file = {}"//nl//"track_rq.open_files.head = {}"//nl//nl//"track_rq.rq_orig = require"//nl//"function require(name)"//nl//" track_rq.nesting = track_rq.nesting+1"//nl//" local orig_ret = track_rq.rq_orig(name)"//nl//" track_rq.nesting = track_rq.nesting-1"//nl//" return orig_ret"//nl//"end"//nl//nl//"track_rq.search_orig = package.searchers[2]"//nl//"function track_rq.searcher(name)"//nl//" local modfun, fname = track_rq.search_orig(name)"//nl//" local nest = track_rq.nesting"//nl//" if fname then"//nl//" track_rq.open_files.count = track_rq.open_files.count + 1"//nl//" if nest > 1 then"//nl//" track_rq.open_files.head[nest] "//"= track_rq.open_files.head[nest-1]"//nl//" for i = 1,nest-1 do"//nl//" track_rq.open_files.head[i] "//"= track_rq.open_files.head[i] + 1"//nl//" end"//nl//" else"//nl//" track_rq.open_files.head[nest] = track_rq.open_files.count"//nl//" end"//nl//" local head = track_rq.open_files.head[nest]"//nl//" table.insert(track_rq.open_files.name, head, name)"//nl//" table.insert(track_rq.open_files.file, head, fname)"//nl//" track_rq.code[name] = modfun"//nl//" return modfun, fname"//nl//" else"//nl//" return modfun"//nl//" end"//nl//"end"//nl//"package.searchers[2] = track_rq.searcher" | This script amends the require and the Lua searcher, such that they report the loaded Lua files in the track_rq table. The filled table can then be used to fetch all required files for the given script. It therefore should be executed before the actual configuration, and evaluated after the configuration script is executed. |
character(len=500), | private, | parameter | :: | rq_store_Lua | = | "rq_store = {}"//nl//"rq_store.file = {}"//nl//"rq_store.code = {}"//nl//nl//"function rq_store.searcher(name)"//nl//" if rq_store.code[name] then"//nl//" local mycode = rq_store.code[name]"//nl//" local myfile = rq_store.file[name]"//nl//" rq_store.code[name] = nil"//nl//" rq_store.file[name] = nil"//nl//" return mycode, myfile"//nl//" else"//nl//" return 'Module '..name..' not found in the rq_store!'"//nl//" end"//nl//"end"//nl//"package.searchers[2] = rq_store.searcher" |
Load the track_rq script into the Lua state.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(flu_State) | :: | L |
Subroutine to pop the code from the tracked required files.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(flu_State) | :: | L | ||||
character(len=*), | intent(in) | :: | modname | Name of the module to pop. |
||
type(cbuf_type) | :: | buffer | Buffer to hold the code. |
Load the rq_store script into the Lua state.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(flu_State) | :: | L |
Push a script in a buffer into the rq_store.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(flu_State) | :: | L | ||||
character(len=*), | intent(in) | :: | modname | Name of the module to store. |
||
character(len=*), | intent(in) | :: | filename | Original file name. |
||
character, | intent(in) | :: | buffer(:) | Actual buffer holding the code. |
Obtain the recorded open files by track_rq from the Lua state.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(flu_State) | :: | L | Lua state to get the requires from |
|||
character(len=PathLen), | intent(out), | allocatable | :: | fileList(:) | List of required filenames in the Lua state. |
|
character(len=LabelLen), | intent(out), | allocatable | :: | labelList(:) | List of the module names associated to the corresponding files. |