Dash:
[t2-trunk.git] / misc / luabash / example / internal.lua
blobe66c1d81dc20cc805336431c428d04590c49ca32
1 -- --- T2-COPYRIGHT-NOTE-BEGIN ---
2 -- This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 --
4 -- T2 SDE: internal.lua
5 -- Copyright (C) 2006 The T2 SDE Project
6 --
7 -- More information can be found in the files COPYING and README.
8 --
9 -- This program is free software; you can redistribute it and/or modify
10 -- it under the terms of the GNU General Public License as published by
11 -- the Free Software Foundation; version 2 of the License. A copy of the
12 -- GNU General Public License can be found in the file COPYING.
13 -- --- T2-COPYRIGHT-NOTE-END ---
15 function plus(a,b)
16 total=bash.getVariable("total")
17 if total == nil then total=0 end
18 prod=a*b
19 total=total+prod
20 print(a.." * "..b.." = "..prod)
21 bash.setVariable("total", total)
22 return result
23 end
25 function callbash()
26 goodresult=bash.call("some_bashy_function", "trash", "test", "a", "is", "this")
27 badresult=bash.call("this-command-is-intentionally-wrong")
28 print ("returncodes were: "..goodresult .. " " .. badresult)
29 end
31 function redirections()
32 repeat
33 a=io.read()
34 if a~=nil then print("xx"..a.."xx") end
35 until a==nil
36 end
38 function printenv()
39 env=bash.getEnvironment()
40 for key,val in pairs(env) do
41 print(key.."="..val)
42 end
43 end
45 function zero()
46 return 0
47 end
49 function one()
50 return 1
51 end
53 function str()
54 return "abc"
55 end
57 function two()
58 return 1, "two" -- :-)
59 end
61 function boolean()
62 return true
63 end
65 -- register shortcuts to functions above
66 bash.register("plus")
67 bash.register("callbash")
68 bash.register("redirections")
69 bash.register("printenv")
70 bash.register("zero")
71 bash.register("one")
72 bash.register("str")
73 bash.register("two")
74 bash.register("boolean")