Skip to content
Afforess edited this page Nov 24, 2016 · 7 revisions

The Factorio Standard Library is written to be directly included in Factorio mods.1.

Adding Factorio Stdlib to your mod

  1. Download the latest release of the stdlib
  2. Unpack the archive, and copy the stdlib/ directory into your base mod directory.
  3. In your control.lua or other lua modules, you can import the stdlib classes you need.
  • To import a stdlib module, use the lua require syntax.
  • All stdlib files are in the stdlib/ directory, and then include the rest of the path to the file.
  • For example, to include the Position stdlib module, the file is in stdlib/position/position.lua, so the import would be require 'stdlib/position/position (note the lack of file extension)
  1. Stdlib modules need only be included once, but duplicate require statements will not cause issues.

Factorio Stdlib layout

Project Files

  • stdlib/area contains position, area, and other geometric utility modules
  • stdlib/config contains configuration utilities, useful for mods with complex configurations
  • stdlib/data contains factorio prototype tools, useful only in the data.law, data-updates.lua or data-updates-final.lau loading phase of Factorio
  • stdlib/entity contains entity and inventory tools. All objects in factorio (ores, assemblers, biters, and the player) are a type of entity.
  • stdlib/event contains the stdlib event manager and time events
  • stdlib/gui contains factorio gui tools and events for managing gui elements more easily
  • stdlib/log contains logging utilities
  • stdlib/trains contains train-specific APIs, as trains differ from standard factorio entities
  • stdlib/ contains lua-specific utilities, outside the scope of just factorio. string, table, and other modules are located here.

Other Files

  • spec/ contains all of the busted unit tests for the Factorio Stdlib. If you have busted installed, you can run the test suite using make test or simply, busted in the main project directory.
  • examples/ contains examples on how to use some of the stdlib code
  • doc/ contains ldoc specific configuration, used for the auto-generated documentation that appears on the github pages
  • build/ is an autogenerated, git-ignored directory that documentation is generated in. It will only exist if you've run make all.
  • circle.yml describes how to auto-generate the github pages documentation using the circle-ci service.

Footnotes

[1] As of this writing (Factorio 0.14), there is no way for mods to share common sets of functions without reproducing the source code in their mod files.

Clone this wiki locally