-- --- T2-COPYRIGHT-NOTE-BEGIN ---
-- This copyright note is auto-generated by ./scripts/Create-CopyPatch.
-- 
-- T2 SDE: internal.lua
-- Copyright (C) 2006 The T2 SDE Project
-- 
-- More information can be found in the files COPYING and README.
-- 
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License. A copy of the
-- GNU General Public License can be found in the file COPYING.
-- --- T2-COPYRIGHT-NOTE-END ---

function plus(a,b)
   total=bash.getVariable("total")
   if total == nil then total=0 end
   prod=a*b
   total=total+prod
   print(a.." * "..b.." = "..prod)
   bash.setVariable("total", total)
   return result
end

function callbash()
   goodresult=bash.call("some_bashy_function", "trash", "test", "a", "is", "this")
   badresult=bash.call("this-command-is-intentionally-wrong")
   print ("returncodes were: "..goodresult .. " " .. badresult)
end

function redirections()
   repeat
      a=io.read()
      if a~=nil then print("xx"..a.."xx") end
   until a==nil
end

function printenv()
   env=bash.getEnvironment()
   for key,val in pairs(env) do
      print(key.."="..val)
   end
end

function zero()
   return 0
end

function one()
   return 1
end

function str()
   return "abc"
end

function two()
   return 1, "two" -- :-)
end

function boolean()
   return true
end

-- register shortcuts to functions above
bash.register("plus")
bash.register("callbash")
bash.register("redirections")
bash.register("printenv")
bash.register("zero")
bash.register("one")
bash.register("str")
bash.register("two")
bash.register("boolean")
