redruin1 / factorio-draftsman

A complete, well-tested, and up-to-date module to manipulate Factorio blueprint strings. Compatible with mods.
MIT License
94 stars 17 forks source link

draftsman-update seems to be running incorrect LUA version #50

Closed quisar closed 1 year ago

quisar commented 2 years ago

Factorio is running lua 5.2. It seems that draftsman-update is running a newer version.

This generates issue with Industrial Revolution mod.

When running draftsman-update the following error is outputted:

lupa._lupa.LuaError: [string "code/items-recipes/recipes-scrapping"]:157: bad argument #2 to 'format' (number has no integer representation)

this is due to the following line;

local average = (minimum+maximum)/2
...
elseif average >= 10 then average = string.format("%d", average)

When average is a float, lua 5.2 is happy returning the integer part, while more modern lua will error out.

draftsman should ensure it runs a lua interpreter with a version compatible with the one factorio is using.

redruin1 commented 2 years ago

Unfortunately, changing the version of Lua that lupa ships with (5.4) is a little more involved than not, which I'm investigating now. Usually I would just overwrite string.format with a custom function to emulate the old behavior, though that seems a little difficult with a function as complex as string.format.

redruin1 commented 1 year ago

After building Lupa from source and manually tweaking it's init.py, I believe I've gotten Lua 5.2 running against draftsman-update. Unfortunately, it requires installing the current master branch from github instead of a wheel from pypi, and manually changing some files. I've raised another issue to figure out what's the best way to select that version of Lua, and hopefully soon lupa 2.0 wheels will be out and it should continue to work "out-of-the-box".

redruin1 commented 1 year ago

It works! Output:

(factorio-draftsman) D:\SourceCode\repos\Python\factorio-draftsman>draftsman-update -p C:\Users\tfsch\AppData\Roaming\Factorio\mods --verbose
Using Lua 5.2 (compiled with (5, 2))
Reading mods from: C:\Users\tfsch\AppData\Roaming\Factorio\mods

Discovering mods...

IndustrialRevolution3Assets1
IndustrialRevolution3Assets2
IndustrialRevolution3Assets3
IndustrialRevolution3Assets4
IndustrialRevolution3

Determining dependency tree...

IndustrialRevolution3Assets1 1.0.7
archive? True
dependencies:
           base >= 1.1.74
         ~ IndustrialRevolution3 >= 3.0.9
IndustrialRevolution3Assets2 1.0.4
archive? True
dependencies:
           base >= 1.1.74
         ~ IndustrialRevolution3 >= 3.0.7
IndustrialRevolution3Assets3 1.0.1
archive? True
dependencies:
           base >= 1.1.74
         ~ IndustrialRevolution3 >= 3.0.1
IndustrialRevolution3Assets4 1.0.1
archive? True
dependencies:
           base >= 1.1.74
         ~ IndustrialRevolution3 >= 3.0.1
IndustrialRevolution3 3.0.14
archive? True
dependencies:
           base >= 1.1.74
           IndustrialRevolution3Assets1 >= 1.0.7
           IndustrialRevolution3Assets2 >= 1.0.4
           IndustrialRevolution3Assets3 >= 1.0.1
           IndustrialRevolution3Assets4 >= 1.0.1
         ? IndustrialRevolution3Projects >= 0.0.1
         ? DeadlockLargerLamp >= 1.5.0
         ? DeadlockBlackRubberBelts >= 1.0.3
         ! IndustrialRevolution
         ! IndustrialRevolutionStacking
         ! deadlock-beltboxes-loaders
         ! space-exploration
         ! boblibrary
         ! angelsrefining
         ! pyrawores
         ! omnilib
         ! Krastorio2
         ! battery-powered
         ! SqueakThrough
         ! LoaderRedux
         ? aai-loaders
         ? Dectorio
         ? textplates
         ? wret-beacon-rebalance-mod

Load order:
['base', 'IndustrialRevolution3Assets1', 'IndustrialRevolution3Assets2', 'IndustrialRevolution3Assets3', 'IndustrialRevolution3Assets4', 'IndustrialRevolution3']

SETTINGS.LUA:
        mod: IndustrialRevolution3
SETTINGS-UPDATES.LUA:
        mod: IndustrialRevolution3
SETTINGS-FINAL-FIXES.LUA:
DATA.LUA:
        mod: base
        mod: IndustrialRevolution3
DATA-UPDATES.LUA:
        mod: base
        mod: IndustrialRevolution3
DATA-FINAL-FIXES.LUA:
        mod: IndustrialRevolution3

Extracted mods...
Extracted entities...
Extracted instruments...
Extracted items...
Extracted modules...
Extracted recipes...
Extracted signals...
Extracted tiles...

Update finished.
hella slick; nothing broke!

Now I can get rid of all the patch code to mimic 5.2. I wonder if I can do some magic in setup.py that downloads the latest master instead of the one from pip and performs the necessary modifications...

redruin1 commented 1 year ago

Lupa has been updated! Moving this from the 2.0 milestone to the 1.0.4 one.