[1.1.107] Game not throwing an error when adding functions in global table

This subforum contains all the issues which we already resolved.
ness056
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun Jul 24, 2022 3:47 pm
Contact:

[1.1.107] Game not throwing an error when adding functions in global table

Post by ness056 »

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))"
Attachments
factorio-current.log
(31.22 KiB) Downloaded 44 times
User avatar
PennyJim
Long Handed Inserter
Long Handed Inserter
Posts: 67
Joined: Wed Jan 18, 2023 3:49 am
Contact:

Re: [1.1.107] Game not throwing an error when adding functions in global table

Post by PennyJim »

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.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2964
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.107] Game not throwing an error when adding functions in global table

Post by boskid »

Thanks for the report. I will end the graceful period of silently ignoring functions inside of `global` with the release of 2.0
Post Reply

Return to “Resolved Problems and Bugs”