So, I get the garbage collection. That's nice info to know.
If I do something like this:
init.lua
Code: Select all
some_variable = {}
some_variable.some_function = dofile(some_function.lua)
some_function.lua
Code: Select all
local some_local_function = function(param1, param2)
local return_value
if param1 then
if param2 then
return_value = true
else
return false = false
end
end
return return_value
end
return some_local_function
And then to get this value in code, elsewhere:
init.lua for some random code elsewhere
Code: Select all
some_other_mod = {}
some_other_mod.some_var = some_variable.some_function(1, 2)
So in the context of the above code, can I load the some_function.lua file, not as a lua file with dofile, but as a text file, using assert(loadstring(text_of_file_as_string))(param1, param2)? If this is true, does this mean that I can subjectively and selectively load and run code, which also provides the smallest the smallest RAM footprint?
On a side note, if the abve is indeed possible, is it then also possible to write lua code to text files and load or reload the lua as runnable code, from say, the world folder, instead of the mod or game folder?
Why would I want to do this? Essentially, to provide a library, and perhaps an API, that can be configured to only provide the functionality desired. A library that can load into memory only the parts of the library actually being used, and subsequently garbage collected, or set to nil otherwise, if no longer used.
MT, being essentially single-threaded, this seems to be a way to provide rich functionality, without the heavy RAM load that some mods impose on the engine. I'm currently building a simple test mod for the Game Dev API project, and what I'd like to achieve is essentially just in time execution of some code, like node registration. If the node data is contained in a .csv file, once the .csv based data had been ran through minetest.register_node, the code for register_node, reading the .csv file, and perhaps other extraneous code could really be unloaded. The .csv loading of the data already trims the amount of lua that the engine has to process at loading, in that there aren't X number of minetest.register_node definitions in the code itself, nor are there node definitions in the lua code that need to be processed, even if through a single function and a lua table. The .csv data exists in a file, the file can be read at will, but the data itself is no longer attached to any executable lua code, and therefore should also trim RAM usage even further.
Does all this make sense? Please, expert lua programmers, teach us better ways to make cool mods?
Shad