aboutsummaryrefslogtreecommitdiff
path: root/lib/os.nom
blob: a797d2b7a3d0a69c363676d7f3e8bcbd70c9977c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env nomsu -V2.5.4.3
#
    This file defines some actions that interact with the operating system and filesystem.

use "core"

action [path of Nomsu file %filename]:
    lua> "for i,f in files.walk(\%filename) do return f end"
    barf "Could not find file: \%filename"

action [sh> %cmd]:
    lua> ".."
        local result = io.popen(\%cmd)
        local contents = result:read("*a")
        result:close()
        return contents

action [read file %filename] (=lua "files.read(\%filename)")
compile [for file %f in %path %body] to (..)
    Lua ".."
        for i,\(%f as lua expr) in files.walk(\(%path as lua expr)) do
            \(%body as lua statements)
            \(compile as (===next %f ===))
        end
        \(compile as (===stop %f ===))

compile [%expr for file %f in %path] to (..)
    Lua value ".."
        (function()
            local ret = list{}
            for i,\(%f as lua expr) in files.walk(\(%path as lua expr)) do
                ret[#ret+1] = \(%expr as lua statements)
            end
            return ret
        end)()

action [..]
    write to file %filename %text, to file %filename write %text
    write %text to file %filename
..:
    lua> ".."
        local file = io.open(\%filename, 'w')
        file:write(\%text)
        file:close()

action [line number of %pos in %str] (=lua "files.get_line_number(\%str, \%pos)")
action [line %line_num in %str] (=lua "files.get_line(\%str, \%line_num)")