date Posted February 1, 2014 Share Posted February 1, 2014 Hello!This suggestion can be interesting only for developers. So if you don't know Lua or Zomboid modding system you won't find nothing for you. So, my main question - why modloader loads EVERY lua file from the "/lua/" directory?I think that this way is totally wrong! That's the same if you write all your java code in single file - do you like that? That way is don't allow to create custom LUA structures for global mods (if someone want to write them).(EDIT: it allows but with help of very tricky ways - timers based on event.Tick and etc) Example:init.lua-- Tables and global vars initializationsomemod = {};include("utils.lua"); --> the analog of dofile() realized from java code, or something similar to that-- Using function from utils.luasomemod.utils:Print("123");utils.luasomemod.utils = {};local utils = somemod.utils;function utils:Print(_text) print(_text);end------------------ I understand that for small mods it's really simple and usefull, but..what about future? What i suggest:Add optional parameter in mod.info, that allow to enable Lua loading only from the /somemod/media/lua/authorun/ directory. For example -lua_authorun=trueIf that parameter is not specifed or false - loads lua from /lua/ directory, else - load from /lua/authorun/. Also need to provide function that allow to run another lua scriptinclude(), dofile() -> anything you want. --------------------- That's all, thanks for reading.Sorry for possible grammar mistakes or rough language.English is not my native language and i really don't want to offend someone. turbotutone and harakka 2 Link to comment Share on other sites More sharing options...
RoboMat Posted February 1, 2014 Share Posted February 1, 2014 <snip>Nevermind. I misunderstood your suggestion. +1 for being able to determine when to run a specific file date 1 Link to comment Share on other sites More sharing options...
Kyun Posted February 1, 2014 Share Posted February 1, 2014 I think I missed the point, tell me if I understood something right : You want to load some of the files of a mod specified by lua_authorun=true, otherwise you will load all files in the mod folder.So only a "main" would be loaded at first (your init.lua), and it would be possible to call ressources (like your print in utils.lua) using a previous "include" only when executing the code ? But the include means load the file if it was not loaded, does it not ? All files would still be loaded at start. I mean imagine you write a C++ app. When you compile, all your code is "put" into an executable. When run all the code is loaded but it's not the same as writting all of it in a single file. The includes are for the compiler to find references. Or do you propose an analog to the inline pragma in C/C++ to optimize where to write functions in the executable to optimize code efficiency ? I'm lost Link to comment Share on other sites More sharing options...
harakka Posted February 1, 2014 Share Posted February 1, 2014 I think I missed the point, tell me if I understood something right : You want to load some of the files of a mod specified by lua_authorun=true, otherwise you will load all files in the mod folder.So only a "main" would be loaded at first (your init.lua), and it would be possible to call ressources (like your print in utils.lua) using a previous "include" only when executing the code ? But the include means load the file if it was not loaded, does it not ? All files would still be loaded at start. I mean imagine you write a C++ app. When you compile, all your code is "put" into an executable. When run all the code is loaded but it's not the same as writting all of it in a single file. The includes are for the compiler to find references. Or do you propose an analog to the inline pragma in C/C++ to optimize where to write functions in the executable to optimize code efficiency ? I'm lost Lua isn't a compiled language so the analogy isn't terribly useful. As far as I understood it, he's asking for a mechanism that allows the mod writer to define a specific entry point where the code execution begins, and then to branch the execution from there in which ever way the mod writer wants, by specifically executing (prolly by some include/require type command) other files. date 1 Link to comment Share on other sites More sharing options...
date Posted February 1, 2014 Author Share Posted February 1, 2014 First of all we should remember that Lua - scripting language. So, any script runs only when we run it.When i mean "include(%file%)" i just saying -> "Hey, please get content of %file% and run it right here" @harakka, thanks you explained it is clear for all! harakka 1 Link to comment Share on other sites More sharing options...
Kyun Posted February 1, 2014 Share Posted February 1, 2014 Thanks to both of you, I got it. You're right lua is not a compiled language so analogies with c are not accurate.So the goal is to load a minimal set of code at start, since we can already branch whenever we want; you can call the entry point of another file and branch, it just happens the file is already parsed - in your case it would be parsed when called. I'm not sure if this will give any performance boost so I still don't see the point. Entry points already exist and are used with events. Nothing will be executed unless tied to an event somehow. From there you can branch however you want. imo, "includes" and such within the code are a horror. Those should be at the top loaded once and for all if they may be needed, or never. It makes debugging and understanding code much easier (if all files were not parsed, you wouldn't know of any syntax error & worse) and allows you to use multiple entry points from the same file, not just one, which is better. if ( a ):from whatever import whatever_I_needelse:from whatever_else import whatever_I_need_2 should never be written like this. Eventually, everything will be imported unless one of them is a one time init that happens when you first launch the game with the mod. There are other ways to solve this using the game datas and the same test. Link to comment Share on other sites More sharing options...
date Posted February 1, 2014 Author Share Posted February 1, 2014 Okay it's your vision.But we was come to that what we start from. You say:imo, "includes" and such within the code are a horror. Those should be at the top loaded once and for all if they may be needed, or never. It makes debugging and understanding code much easier Okay, but what about situation when you need run your scripts in specified order?Why? Example in first post - if you want to make structured code.Of cource you can put all your code in single file, but what more easier for you - one file with 10k lines or 10 'themed' files like "utils.lua"---Moreover, think about future - when mods will much more global, when Zomboid will have serverside and clientside lua code. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now