Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small errors found with trains/events #144

Open
chrisgbk opened this issue Sep 22, 2019 · 6 comments
Open

Small errors found with trains/events #144

chrisgbk opened this issue Sep 22, 2019 · 6 comments

Comments

@chrisgbk
Copy link

error('Detected attempt to register an event using script.' .. name .. ' while using the STDLIB event system ' .. id and id or '')

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:

Trains.on_train_id_changed = script.generate_event_name()

Should use Event module, not script directly, as the Event module overrides script to error when called directly.

@Nexela
Copy link
Collaborator

Nexela commented Sep 28, 2019

Ok, I have this fixed for the next release because I forgot to check issues before the last release. Go ME!

@Nexela Nexela closed this as completed in 681ad9b Sep 28, 2019
@chrisgbk
Copy link
Author

Forgot to include the required event_name string parameter when using Event.generate_event_name() in the patch.

@Nexela
Copy link
Collaborator

Nexela commented Sep 30, 2019 via email

@Nexela Nexela reopened this Sep 30, 2019
@OvermindDL1
Copy link

OvermindDL1 commented Sep 30, 2019

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...

@aSemy
Copy link

aSemy commented Mar 15, 2022

@Nexela @OvermindDL1 TypeScriptToLua and Typed Factorio solve the strongly-typed Lua problem :)

@OvermindDL1
Copy link

@aSemy It does! I've been using typescript to lua for a while now, it works really well! It generates very nice output too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants