2010-07-11

Vala for scripting

Hello,
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 vala
message ("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.

10 comments:

  1. Is there a way to get the command line args in this mode (without a main function)? And how do I use a package?

    #!/usr/bin/env vala --pkg gtk+-2.0

    does not work:

    /usr/bin/env: vala --pkg gtk+-2.0: No such file or directory

    ReplyDelete
  2. 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).

    ReplyDelete
  3. This seems nice at first, but is it really that useful? I will just stick with languages that are really designed for scripting.

    ReplyDelete
  4. Why no cache? There needs to be a cache option... python has .py an .pyc ... .pyc is only created on imported modules IIRC though...

    ReplyDelete
  5. @blog reeper, it's not implemented yet
    @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).

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

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

    ReplyDelete
  7. Best 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).

    It could been better than global environment variable.

    ReplyDelete
  8. This is something I've found incredibly useful - I hope it's kept in the language.

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

    ReplyDelete