Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Get started modding Factorio in TypeScript (cdaringe.github.io)
69 points by cdaringe on Jan 25, 2021 | hide | past | favorite | 12 comments


I did not know that a TypeScript to Lua transpiler existed!


I'm also pleasantly surprised by this transpiler discovery.

4 years ago I was managing a Feed The Beast (A heavily modded and themed Java Minecraft version) server and in that mod packages was OpenComputers (https://ocdoc.cil.li/) which exposed a lua api and in game computers to the players. The OpenComputers Package Manager (https://github.com/MightyPirates/OpenComputers/blob/master-M...) became a limiting factor to my players as they wanted some ability to load from other sources so I converted the program to MoonScript (https://moonscript.org/) and maintained a fork with modifications for them.

MoonScript was certainly more pleasant to write and maintain (compared to Lua), but type safety would've definitely helped squash some of the weirder side effect driven bugs. That said, I still think MoonScript is a great middle ground for things that are written in Lua but need some extra organizational tools.


I understand the appeal of type safety, but will we ever see the end of this trend of overstating its value?

At what point is the value of type safety offset by the complexity of transpiling scripting languages? TS is a superset of JS, so that is at least a pretty simple conversion... but TS to Lua?


You're remark suggests that there is a trend overstating the value of safety. I'd argue that there is a trend under stating its value. Given that it's all subjective, I would ask a different question, which would be "when will we begin to see a trend of people appreciating diversity of opinion on the matter."

Honestly, I would have preferred not to author the project. Instead, I would have preferred to mod straight in c++, rust, vlang, or some other machine-level code that factorio would compile on load and link in. But, the factorio team didn't offer this to me, and I appreciate their diverse values, suggesting that Lua is adequate.


> You're remark suggests that there is a trend overstating the value of safety. I'd argue that there is a trend under stating its value.

I guess all I can do is disagree there.

> I would ask a different question, which would be "when will we begin to see a trend of people appreciating diversity of opinion on the matter."

I don't think it's a matter of respect. I think it's just the result of a simple cost-benefit analysis.

It's costly to support additional runtimes in your application. That's why despite the popularity of many JS alternatives, none of them are natively supported by browsers. Chromium even has a branch with a native Dart runtime but Google's own web browser doesn't want to take on the added cost of supporting Google's own web scripting language[0].

> But, the factorio team didn't offer this to me, and I appreciate their diverse values, suggesting that Lua is adequate.

I assume they didn't chose Lua because of the language syntax. I'm sure they chose it becaude it's a language intentionally designed to be easy to embed into other applications. Lua even describes itself as "lightweight" and "embeddable"[1].

[0] https://news.dartlang.org/2015/03/dart-for-entire-web.html

[1] https://www.lua.org/about.html


I regard lua as essentially trivial to embed and to use to script a host application. The ease of hooking to/from the host application written in C is very straightforward and painless. Its possible to have lua call C which calls lua which could call C. That reentrancy is underrated but so very useful.

The simple design also means you can have multiple independent lua interpreters with no overlap. Isolation is quite achieveable with no real effort. Just create a new lua state.

Contrast this with python. Ouch. But python also supports embedding and can import C functions etc. Quite a bit more effort though. Multiple interpreters isn’t so nice. Not when you've experienced lua's ease of embedding. The GIL isn’t great either but not a big deal if everything about a script is in a single thread.


I'm low vision / blind and the other day I sat down to try to make Factorio self-speaking. I wanted to be able to hover over items in the inventory and have the game speak what they were, as a start. Though I like the docs pretty well and I got as far as having the game read chat messages aloud (you can dump to a file and I wrote a little speech server to check the file for updates and read its contents if it changed on disc), the names and descriptions of items aren't available to the API, which seems like a pretty basic oversight. I could likely have implemented a reading of structures clicked on in the game world, but not of items in the inventory.


It's not an oversight (there has been much discussion about this limitation on the forums), more a consequence of some of the design decisions of how mods work: factorio runs a lockstep simulation model, so all the clients need to operate deterministically and consistently across for all players. This includes the mods, so the modding API is deliberately restricted to only information which is in common between all players. Due to internationalisation, the names and descriptions can be different between players, and this could easily introduce desyncs between players.

Now, there's a bunch of possible solutions to this problem (I think the best approach is to have the concept of a UI mod which can affect the interface but not the game world. As an added benefit you could allow users to have different sets of UI mods installed and not depend on the server using it), but the engineering effort involved is not so simple as just adding another part to the API (and factorio developers are generally going to try to do something well if they do it).


the descriptions is no surprise, but the names is. player.get_inventory Id think would have enough to get going. https://lua-api.factorio.com/latest/LuaControl.html#LuaContr... did you hit a dead end there?


Getting the inventory doesn't really do anything. What I need is the inventory item under the cursor.

Some more context:

https://forums.factorio.com/viewtopic.php?f=25&t=93690


This couldn't have come a at a more convenient time. I was looking this weekend to write my first mod but was struggling to learn both Lua nd the Factorio API at the same time.

But just curious, does anyone thing a regex train renamer sounds like a good idea? I'm thinking you can select an area then change all stop, stations and schedules according to a regular expression.


This sounds cool for sure.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: