Hello there,
In this page of the LUA API docs, it is said that "Functions are not allowed in global and will throw an error when saving.", however if you add a function in the global table (for example with this command "/c global.foo = function() end") the function will be added in the global function and will not be conserved through save/load cycle but it will only log a warning. This is really confusing because it is not what the docs says. Although I don't know which one is better between adding an error or modifying the docs.
Also I'm quite curious why it is impossible to add functions to the global table? I would imagine it has a link with the fact that the load function doesn't work with binary chunks but it doesn't help me much to understand.
The following log file is me:
- creating a new save
- running "/c global.foo = function() end"
- running "/c log(type(global.foo))"
- saving and reloading the save
- running "/c log(type(global.foo))"
[1.1.107] Game not throwing an error when adding functions in global table
[1.1.107] Game not throwing an error when adding functions in global table
- Attachments
-
- factorio-current.log
- (31.22 KiB) Downloaded 44 times
Re: [1.1.107] Game not throwing an error when adding functions in global table
I hypothesize that it is something to do with the fact that commands can see all global tables.
I don't know which global table you're putting that function in, and I wouldn't be surprised if the choice to not crash on saving the command global or things in global added specifically by commands was intentional.
This is all hypothesis that I can't currently validate though.
I don't know which global table you're putting that function in, and I wouldn't be surprised if the choice to not crash on saving the command global or things in global added specifically by commands was intentional.
This is all hypothesis that I can't currently validate though.
Re: [1.1.107] Game not throwing an error when adding functions in global table
Thanks for the report. I will end the graceful period of silently ignoring functions inside of `global` with the release of 2.0