jow- / ucode

JavaScript-like language with optional templating
ISC License
87 stars 24 forks source link

The stdout of system calls be inline with the template, instead of at the begining. #124

Closed okibcn closed 1 year ago

okibcn commented 1 year ago

The stdout of system calls be inline with the template, instead of at the beginning.

For instance, lets create a file called test.ut with the following content:

The location of vi is {% system("which vi",0); %}
And the location of sh is {% system("which sh",0); %}

This is the expected output

$ ucode -T test.ut
The location of vi is /bin/vi
And the location of sh is /bin/sh

Instead, it outputs this:

$ ucode -T test.ut
/bin/vi
/bin/sh
The location of vi isAnd the location of sh is

To be similar to Lua, it should deliver the stdout of a call not before everything else but in the right place.

jow- commented 1 year ago

system() != LuCI's call(). Also {% %} is a statement block. You need an expression block ({{ }}) if you want to treat the expression result as output.

A working example could be:

{% import { popen } from "fs" -%}

The location of vi is {{ popen("which vi").read("all") }}
And the location of sh is {{ popen("which sh").read("all") }}
root@er-x:~# cat /tmp/test.ut
{% import { popen } from "fs" -%}

The location of vi is {{ popen("which vi").read("all") }}
And the location of sh is {{ popen("which sh").read("all") }}
root@er-x:~# ucode -T /tmp/test.ut
The location of vi is /bin/vi

And the location of sh is /bin/sh

root@er-x:~#