The Lua source code to the "base mod" is (necessarily) included in the game. You can read it if you have a copy of the game, and the modding API is fully documented: https://lua-api.factorio.com/
Those two are definitely not incompatible. Take Karia[0] for example, which is fully Free Software[1].
[0] https://store.steampowered.com/app/1261430/Kandria/
[1] https://github.com/Shirakumo/kandria/blob/master/LICENSE
Fun story:
Somebody independently recreated the core engine themselves to prove a point about multi-threading. Imagine recreating an entire game engine in 50,000 lines of C++ to prove a point, yeah, it happened: https://www.reddit.com/r/factorio/comments/jizq1b/comment/ga... What a legend!
Basically - tests, reproducibility, and dedication to tracking down "weird minor bugs" before they become "major show stoppers".
https://lua-api.factorio.com/latest/
They also ship a full .pdb file with the Windows binaries (presumably for stack traces), so you can get a lot of information with dia2dump, or dig in with WinDbg.