the upcoming release of Vala will have basic scripting capability (mostly for small tests). Yes, this sounds weird, but it's more trivial than what you expect. The installation will create a symbolic link /usr/bin/vala -> /usr/bin/valac that you can use to run vala scripts.
Also, vala scripts can have implicit main(), so that it becomes faster to write test scripts. An example:
#!/usr/bin/env valamessage ("test");
Save it as test.vala, now you can either chmod +x test.vala and run ./test.vala or just vala test.vala.
Valac will automatically compile the script and run it. After that the executable will be deleted, which means there's no cache.
This feature is of course experimental and it's not currently possible to import other vala files.
Is there a way to get the command line args in this mode (without a main function)? And how do I use a package?
ReplyDelete#!/usr/bin/env vala --pkg gtk+-2.0
does not work:
/usr/bin/env: vala --pkg gtk+-2.0: No such file or directory
Stephen, those are all limits of the implementation, it's still really basic. For what concerns the args, there was a cheap talk about making them global (like in a variable).
ReplyDeleteThis seems nice at first, but is it really that useful? I will just stick with languages that are really designed for scripting.
ReplyDeleteWhy no cache? There needs to be a cache option... python has .py an .pyc ... .pyc is only created on imported modules IIRC though...
ReplyDelete@blog reeper, it's not implemented yet
ReplyDelete@Jiří Zárevúcký, nobody says you're going to create an entire project as scripting, but it's useful for tests (well not that much until you can specify packages).
It's great watching Vala. I've written a few toys in it any look forward to having the time to use it properly at some point.
ReplyDeleteI just love the way ideas seem to froth out of the project. I think this is one of them. I'm quite sure not all will be successful but just to see so many sparks developed far enough to find out.
It just feels like there aren't many pessimists in the core team ;-). Good.
@Luca Bruno: I guess you're right.
ReplyDeleteCan we expect a REPL ?
ReplyDeleteBest solution would be probably adding special function, like get_args(int out count, string[][] out args). Sorry, but I don't know i remember vala syntax :-p . You can also define some iterators function to get one argument by one(like shift).
ReplyDeleteIt could been better than global environment variable.
This is something I've found incredibly useful - I hope it's kept in the language.
ReplyDeleteWhen I can't remember how the string slicing works compared to Python or something like that it's really handy to be able to write a quick three line script.