#Phobos discussion
1 messages ยท Page 1 of 1 (latest)
a thread.
yea it doesn't. I/we might request that to change now, but for now you gotta --use-load
that doesn't seem to be documented anywhere
did you talk to therenas or jarg about it
I know it through jarg, yea. It has been a topic in #mod-dev-discussion in the past
i was the one who did it
it was going to get locked down entirely and i pushed back and got to save load loading bytecode
i suspect if phobos gets popular it might be permissible to relax it back
what if you had a wrapper script that would automatically compile mods for you
especially since we're now doing a little sanity checking on the loaded bytecode too, to keep it from doing anything to crazy
for free (minor) performance benefits
yep
that'd take a bit more doing
there'd also be the issue of compilation taking time. I suspect release builds with a bunch of optimizations on big mods to take minutes, but that's a very rough guess
yeah that'll get interesting
kinda want to talk to jcranmer on the topic of compiler optimizations
he has a fair bit of domain knowledge
I might also look into multithreading libs for that, but those are troublesome
"do you want to install the recommended extensions for this repository?" :p
but yeah, factorio's strictness around bytecode is basically defence against memory bugs in the vm, all the ones we know about have been fixed, but it's hard to say if that's really all of them...
that's what the project is setup with/for, so might as well recommend it ๐คท
luckily/unfortunately it's hard for me to read so I can't play around with that too much. But I've learned a few things looking through it
Yay! ๐
hard to read because it's all lua's c-programmer-disease macros?
mhmm :D
Ultimate awesomeness would be getting phobos down to a single executable binary, but I'm not sure that that's even possible with lua
Oh something I didn't make super clear: the debug build profile currently disables tailcalls, which I find to be very useful. (release is default for the record)
mhm
just ship a single native binary
alternatively, do the sane thing and ship a (VM? interpreter? idk)
single binary of a lua vm that just loads a bytecode blob on startup is probably not too hard to do
Sounds incredibly hard to a noob like me ๐
C is ridiculously easy to compile if you're on Linux ๐
make
Bam!
||Sometimes||
gcc, you mean
but separate .lua file for phobos in a factorio mod is still useful for other mods that want to consume code from a user
which might want to invoke it in-game on those little bits of code from textboxes
๐ค I haven't thought about how it would work with library mods
perhaps a FUSE fs for resolving deps
library mods compiled with Phobos (or the Phobos mod itself) is pretty interesting. In the end it will probably have an option to include the external libraries directly into the compiled files, or to link to their compiled files. I'm not sure, it's going to be hard
Honestly, if we want full optimization and interlinking, the best solution would be to include libraries in your mod. But then that removes the entire advantage of mod portal dependencies
Oh, you just said the same thing lol
It's possible... as long as you don't play multiplayer
sounds like a dependency tree resolution problem
Unless we get wube to compile base using Phobos
Unfortunately they need to actually document their stuff first, otherwise you wouldn't know what is available
well, it's a crc issue. behavior would mostly be the same, unless some compiler flags are set that allow it to do evil things
That's the other big reason for including libraries - if you include compiled phobos files, you can't go to definition to see how anything works
i'm not sure static libs is really a good appraoch
you can still call require directly to get stuff from other mods just fine
you can ship a sourcemap
and if that happesn to load a phobos compiled blob, great, if it loads plain lua, whatever ๐คท
true, but what if the compiler wants to be able to figure out what type (return value) it gets from that, and functions from the required file
That would work
and regarding source, you can still include your .pho source files if you want to. the bytecode itself points to .pho files in it's source field
(or publish them separaately, for non-phobos libs)
hm, yea that makes perfect sense actually
๐ค Could phobos compress the entire mod into the base files if it wanted?
(control.lua, data.lua, etc)
Yep it could
that gets complicated in some cases, but yes in theory it could
is .. optional chaining?
Oooh lambdas
what language does that useage of || come from? i've never seen it anythign other than logical or?
JS has it
Yeah, JS
like foo || bar?
yeah
Also Rust
it's the counterpart of &&
but i still dont' understand what you're refering to with this
because that's... not ||
"truthy" ? "truthy" : "some other value" is what I really meant
for ??, the equivalent is:
if (value === undefined || value === null) {
value = rightHandSide
}```
another one that may or may not be useful is the pipeline operator
you mean for bitwise or? so syntatic sugar for bit32.lor (right?)?
no
|| is literally exactly the logical or that lua already has as or, ?? is just that but instead of testing truthiness it explicitly tests against nil
that's the only version of a single | I know (which is from c#)
iirc ?? was always on my "eh, maybe?" list
yes, single | is bitwise, but nobody's talking about that :)
another one that may or may not be useful is the pipeline operator
it's how I parsed that statement, but regardless, it's resolved :P
Same. Mostly because it's not obvious if it's checking for nil or falsy
just look at https://github.com/tc39/proposals/ for inspiration
(pipeline operator is different, btw: https://github.com/tc39/proposal-pipeline-operator)
Anything javascript related is very most likely out the window. I dislike the language and believe it's syntax is simply bad. I'll take a look at it, sure, but I'm definitely biased to say "no"
I believe that at this point JS is borrowing stuff from other languages to make it nice to use
so you shouldn't be biased against modern features
everyone is borrowing from everyone these days
but there's plenty on the list already :p
well, we do have raweq...
(i'm not suggesting that === should be sugar for it though, in general i think symbols that are sugar for more function calls are asking for trouble down the line)
True, I forgot about raweq
in general i think symbols that are sugar for more function calls are asking for trouble down the line
good point... though for some things it's really tempting
But at least Lua doesn't automatically try to type coerce when you use ==
In javascript, "2" == 2 is true and I hate it with every fiber of my being
super tempting, but what happens when someone assigns something else to that function? :D
that function that you're presumably getting, at lesat originally, from a global
Phobos has to be smart enough to keep the function it actually wants in some local/upvalue ;)
or maybe they replaced it for a good reason, and you should use the replacement
so operator overrides?
well... yea that's an issue
yeah, it's a tricky subject, which is why my general reaction is to leave it to the vm to decide that sort of stuff
(where the metatables/operator overrides are happening)
The one time i thought about inlineing metamethods it seemed like a good idea because it makes things like Postion math more usable
but yea, i didn't think about it much
(besides, JS syntax is just C-like syntax)
I suppose the definition of syntax matters at that point. I consider the real meaning of some syntax, so what it actually ends up doing, to be part of the syntax, because it ultimately affects how I read code. But that's semantics at that point, and I'd rather just leave it at "I don't like JS"
yeah let's discuss... something else, that doesn't incite tensions and language flamewars

do you have brackets for begin/end planned or done?
back when it was my project htat was alwasy a hard no
nope, because it breaks far too much syntax, which means it would require a big change in syntax, making even "just" an option to allow for it unreasonable
not even as a preprocessor that replaces them with the appropriate keywords?
would it really improve the language though?
if foo {
}
what the heck do you mean ๐ฅ
(if it's not clear, that's ambiguous between a function call and a block)
ah right, that was the main issue
i've never heard anyone argue for braces actually explain a way in which they improve the language, rather than just being "what i like"
and you can't simply remove implicit calls because of the goal to remain a strict superset of lua
It would improve navigation. I cannot count how many times I have had to scroll up and down to make sure I have the right end for the then/do. If the language used brackets then I could just hit m to jump to the matching one, and it would work with bracket coloring.
that's a language server deficiency to find the matching keyword :p
they can do it for words just as well as they can for brackets
The language server does highlight it when I hover it. But it doesn't remain highlighted as soon as I move off of it
So I can't use that when it's more than a screen tall
because of the goal to remain a strict superset of lua
*
- Some features can end up breaking regular Lua code, such as adding a
switchkeyword. That's something I'm fine with, but any such features will be opt in
what strategy would you use to implement switch?
it always annoyed me that hte vm doesn't support the computed-jump needed to do it "correctly"
That's one hard question. Some way where it doesn't need to recreate a table and a bunch of closures every time
I did notice something though, which i didn't investigate yet, but it might help... maybe. one sec, let me get the screenshot
yeah if you do a table of functions for the easy dispatch then you get so many complications about linking upvals right
but you could also just try and work out an efficient tree of ifs for it
to keep it all inline within the function
tailcall just kind of continues?!
this tailcall weirdness is actually a bit of a tangent, now that i think about it, but yea everything you said previously is exactly my train of thought
and i haven't decided yet
oh
you can't actually tailcall c functions
if you try to it turns into a regular call
i dunno if that's actually relevant though
hm, i'll try with a Lua function then
but i'm looking at OP_TAILCALL in the vm now and it looks like it does the thing by actually replacing the current function on the lua stack with the other one
so i'm not entirely clear on how it would continue from it if it really did tailcall
i assume the extra OP_RETURN is to deal with if it turns out to have been a c function
and therefor the lua function is still on the stack to be returned to
but yeah, have a look at vmcase(OP_TAILCALL and luaD_precall
yea it does return if it's a Lua function. Alright, not useful then but still interesting
arguably the return after tailcall should probably be required then ๐ค
I did, but didn't understand much of it ๐ (well not actually luaD_precall, but tailcall itself)
the improtant bit is to see that it does basically nothing for c functions and all that extra shit for lua functions
I can't think of anything that would cause issues (in regards to memory/security), but better save than sorry
the one i'm imagining is if you run off the end of a function
but i'm pretty sure the vm will stop you there anyway
but yeah, i'll probably go add that to the bytecode sanity checks later before anyone does discover something evil to do with it
I've looked into this a bit and thought about it. I can definitely see it's use, but interestingly enough I mostly remember having the issue the pipe operator solves in C# but hardly in Lua. While I'm not entirely certain what the cause of that is, I believe it's related to Lua mostly using pure (ish) functions and very few class like objects. While it is possible to have a coding style using a lot of metatables and userdata objects (if the c libraries use them), I myself tend to use those pretty rarely. (Inspired by factorio, and I've grown to like the simplicity of it).
Now I do see it's pros, I cannot look past the cons. I've ignored its origin, I'm sorry for not remaining object objective earlier, and when looking at it the first time, without any context, it was nearly impossible to guess what it could mean; What that code was doing. When reading that it is meant to solve/improve big nested expressions or function call chains I could guess what it was doing, but still wasn't certain. Only once I read its actual description for how it works it made sense. While this is fine and part of learning a language, it is still a downside I like to avoid, and as I mentioned previously I don't actually see much gain from it specifically in Lua and in factorio.
Lua currently suffers from very little obscure syntax (see for and metatables), so unless this pipe operator |> becomes very commonly understood, I consider it unlikely. (Note that my opinion is very mutable through many means)
I do agree that it gets a bit difficult to understand wtf is happening
but that's pretty much always in the case where it's already difficult to discern
That's true, but it wouldn't just end up being used in cases that are difficult to discern currently, if that makes sense
Hm, i think this is a good (long winded) way to put it:
Complex/Weird syntax is fine and to be expected as long as it is kept to a minimum.
Lua's manual is quite literally a single page, where you can read the sections about its syntax in like an hour (rough estimate). Adding a little bit of complex syntax to that is fine, because at the end of the day it's still not a lot of syntax. Now imagine a language that has nearly every syntax any language has implemented in some way shape or form... While each individual piece of syntax is easy to understand if you read through the manual about it for 5 minutes, you still don't know what's going on. I think a great example of this is powershell or bash or whatever it's called. Unfortunately looking up some specific syntax you don't understand is very difficult, because you don't know the name of it.
A temporary variable beats pipeline operator on readability 10 times out of 10.
ah, the "pretend i'm writing a shell script" operator :p
Actually, even better way to put it: The less syntax, the better. ๐
and yes, keeping it simple enough to explain in one page seems good :)
(obligatory note: @feral geyser we (at least I) are/am not arguing against you, but the syntax/nature of languages)
programmer-debate mode where the people disappear and the ideas fight it out
โ๏ธ 
sockpuppet for ideas mode
*