Open chrisgbk opened 4 years ago
Ok, I have this fixed for the next release because I forgot to check issues before the last release. Go ME!
Forgot to include the required event_name string parameter when using Event.generate_event_name()
in the patch.
Sometimes I wish lua was more strongly typed! Or my memory wasn't so!
On Sun, Sep 29, 2019, 7:44 AM chrisgbk notifications@github.com wrote:
Forgot to include the required event_name string parameter when using Event.generate_event_name() in the patch.
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/Afforess/Factorio-Stdlib/issues/144?email_source=notifications&email_token=ADKTFYETPUWI6ADFABW7TNTQMCIKRA5CNFSM4IZBPT32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD73SBOY#issuecomment-536289467, or mute the thread https://github.com/notifications/unsubscribe-auth/ADKTFYD5MJ77CSWA4XCX5PTQMCIKRANCNFSM4IZBPT3Q .
Sometimes I wish lua was more strongly typed!
Well Metalua can perform strong typechecking at runtime, though there is a runtime overhead for it.
typedlua is a preprocessor that takes a typed lua (performing type checks) to convert to normal lua without the annotations. It's deprecated as the authors are working on a new language called Titan,owever, Typed Lua is supposedly 'fully functional' and has no runtime overhead, generates standard LUA 5.1 (which is what factorio uses as I recall?), instead you'd just run the typedlua lua program over the 'tl' (typed lua) source code files to generate normal lua files, that could then be used as normal. On a plus side mod authors could use either normal lua, or they could use typedlua against stdlib's typedlua files so they could be statically typed as well (further bonus if stdlib 'types' the entire factorio api, even that which it does not use). In addition it can be loaded at runtime as well (as the typedlua engine is still just normal lua code) if for some reason you want to perform runtime checks.
Or of course use titan straight, less of a lua with types
and more of an enhanced lua that still outputs normal lua
, with support of lua up to 5.3.5. It's still very incomplete though so I doubt it will be sufficient by any stretch, but maybe something interesting in the future.
Or lastly, the crème de la crème of strongly statically typed lua is of course the Haxe Programming Language, the language that compiles to dang near everything in existence, including being able to output LUA. You'd just write normal haxe code, it output normal lua files when you run the haxe compiler, all statically and strongly type checked. Users of stdlib would be able to write lua or haxe code. It generates very ugly although very efficient code, it does add about 300 lines of prelude as a set of helpers for lua access that aren't intended for use by end user and thus aren't exported, they can be ignored, though there are lots of useful things like being able to add injection trace calls (wonderful for debugging) among a lot more.
Though my dream would be for factorio to drop lua and just wasm instead, it would be faster, even better sandboxed than lua, and you can use it with whatever language you want, or even mixture of languages, including lua. And with the WASI spec finally standardizing it's all even easier! If only... ^.^;
Hmm, interesting idea though, a Haxe project management for mod authoring in factorio... Strong Static typing would just outright prevent so many classes of common bugs that happen in mods...
@Nexela @OvermindDL1 TypeScriptToLua and Typed Factorio solve the strongly-typed Lua problem :)
@aSemy It does! I've been using typescript to lua for a while now, it works really well! It generates very nice output too.
https://github.com/Afforess/Factorio-Stdlib/blob/f371fc4e339376416d13fd434e623cdfecd8d250/stdlib/event/event.lua#L68
Should be:
error('Detected attempt to register an event using script.' .. name .. ' while using the STDLIB event system ' .. (id and id or ''))
If this branch gets executed, the result is
attempt to concatenate local 'id' (a nil value)
instead of the actual intended error occurring, due to .. having higher precedence than and/or.Which leads to:
https://github.com/Afforess/Factorio-Stdlib/blob/f371fc4e339376416d13fd434e623cdfecd8d250/stdlib/event/trains.lua#L26
Should use Event module, not script directly, as the Event module overrides script to error when called directly.