Closed runlow closed 2 years ago
I believe having it be part of the code chunk makes sense, since it's part of the code. It's not something that changes often, and it makes sharing code snippets clearer.
@RobLoach Apologies but I don't follow. What's the downside to being able to specify the language in the chunk header with an extra (currently unused) byte? It would not stop people from still being able to use the current syntax if they want to.
Not sure I understand how it changing often or not is relevant, or how it "makes sense since it's part of the code". Do you care to explain?
As an aside - did you know that file extensions (foo.js
and foo.lua
) are completely ignored in tic80 pro?
In other words if you have // script:js
at the start of the file - it ignores the fact your file is *.lua
I think since the extension check is meaningless as is already - it should not check for extensions at all and just check for null bytes to see if it's an plaintext file
If you're looking to save code space, and are using JavaScript, just 13 bytes won't really help you. I'd recommend...
It isn't just the golfing. Having to add // script:js
each time seems pointless if the file is already foo.js
. If it doesn't care for "file extensions" then it should not check for them either - in my mind, maybe I'm wrong.
Lets not forget there isn't always file or a filename... snippets of code are often handed about / copied pasted, etc...
ok @runlow how do you see the setting of this flag from the code editor?
@joshgoebel the snippets would still work the exact same way as now, if the coder doesn't add // script:foo
or doesn't specify the language (by saying what it is) it's on them - to remember doing so. It's not like they usually explicitly state the language when they share code in Lua - people assume it's Lua.
@nesbox I don't think it would need to be necessarily set from the editor, as long as the "language byte" is in the chunk header it would work - everything else could behave the same way as it does now. The editor could recognise that the cart was loaded with that chunk header and therefore interpreting code in that language. If the user decided to use // script:foo
it would overwrite what's in the chunk header. This could be a hidden feature (like the separate chunk id for compressed code) - possibly later added to the editor if there is need/demand.
As for how it could work if it were to be set from editor - it could be an icon that cycles between LU/JS/MS/WR/FN/SQ each time it's clicked but for now it could be hidden.
If the user decided to use // script:foo it would overwrite what's in the chunk header.
This is surely a neat and easy way to do it. The only support case would seem to be someone who empties out a cartridge and tries to switch it from one language to another without the magic comment... they will be in a world of hurt... but I think I could agree that seems a pretty narrow edge case so that's not a great argument against.
But this request itself also seems a very narrow edge case... [without providing any UI] we're suggesting adding a very hidden feature, just for code-golfers, that is accessed by:
I think my vote would be this is a lot of effort for very little payoff, but ultimately it's up to nesbox. :-)
OK, thank you for the ideas...
Added CHUNK_LANG
to the cart and ID
to define a language
CHUNK_LANG (1 byte):
10 - Lua
11 - MRuby
12 - Js
13 - Moon
14 - Fennel
15 - Squirrel
16 - Wren
17 - Wasm
10d852a8446bd306eed375eaa64e7ee501bde435
How does one set lang
?
Using an external tool, or you can save it as a project.lua
or whatever and add LANG
tag manually, then save as a .tic
-- <LANG>
-- 000:0a
-- </LANG>
AHHHHH, I missed that because it's so small a patch because it's using the existing binary section logic. :-) Nice.
Everything would work the same way as current, except you could also specify the language in the chunk header (in the unused byte), rather than as a comment.
For example 0 could be Lua, 1 Javascript, 2 Moonscript, 3 Wren, 4 Fennel, 5 Squirrel, etc
In other words it would no longer be necessary to have
...at the start of the code chunk payload but if you did that anyway it would still work like it does now
Motivation: to give non-lua languages a chance for golfing/sizecoding carts because that extra line is an extra 13 bytes Motivation: not having to write
// script:js
each time in all *.js files