call system executables from undefined function calls
This commit is contained in:
parent
40fba4716b
commit
ffef8a96e7
4 changed files with 26 additions and 16 deletions
27
ast/eval.go
27
ast/eval.go
|
|
@ -19,6 +19,9 @@ package ast
|
|||
|
||||
import "gitlab.com/whom/shs/log"
|
||||
|
||||
var CallExecutablesFromUndefFuncCalls = false
|
||||
var CallExecutableToken = "l"
|
||||
|
||||
func (t *Token) Eval(funcs FuncTable, vars VarTable) (*Token, bool) {
|
||||
if t == nil {
|
||||
return nil, false
|
||||
|
|
@ -69,13 +72,29 @@ func (t *Token) Eval(funcs FuncTable, vars VarTable) (*Token, bool) {
|
|||
return nil, false
|
||||
}
|
||||
|
||||
//if symbol in front of a list, could be a function call
|
||||
if ret.Tag == SYMBOL {
|
||||
f := GetFunction(ret.Inner.(string), funcs)
|
||||
if f == nil {
|
||||
log.Log(log.DEBUG,
|
||||
"could not find definition for symbol " + ret.Inner.(string),
|
||||
"eval")
|
||||
return nil, false
|
||||
if CallExecutablesFromUndefFuncCalls {
|
||||
f = GetFunction(CallExecutableToken, funcs)
|
||||
if f == nil {
|
||||
log.Log(log.DEBUG, "Symbol " + ret.Inner.(string) +
|
||||
" has no definition in function table. Additionally " +
|
||||
"the configured LoadExecutableToken is also not defined",
|
||||
"eval")
|
||||
return ret, false
|
||||
}
|
||||
|
||||
// see the use of CallFunction below
|
||||
ret = &Token{Next: ret}
|
||||
|
||||
} else {
|
||||
log.Log(log.DEBUG,
|
||||
"could not find definition for symbol " + ret.Inner.(string),
|
||||
"eval")
|
||||
return ret, false
|
||||
}
|
||||
}
|
||||
|
||||
return (*f).CallFunction(ret.Next, vars, funcs), true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue