add list functions to stdlib
This commit is contained in:
parent
49ea765e40
commit
b01415d786
4 changed files with 146 additions and 12 deletions
|
|
@ -22,22 +22,22 @@ import "git.callpipe.com/aidan/shs/log"
|
|||
type Operation func(*Token, VarTable, FuncTable) *Token
|
||||
|
||||
type Function struct {
|
||||
function Operation
|
||||
name string
|
||||
timesCalled int
|
||||
args int // TODO: Make this a list of expected types (TAGs)
|
||||
Function Operation
|
||||
Name string
|
||||
TimesCalled int
|
||||
Args int // TODO: Make this a list of expected types (TAGs)
|
||||
}
|
||||
|
||||
type FuncTable map[string]*Function
|
||||
|
||||
// TODO: Currently only checks arg list length
|
||||
func (f Function) ParseFunction(args *Token) bool {
|
||||
// HANDLE EXEC
|
||||
if f.args < 0 {
|
||||
// handle infinite args
|
||||
if f.Args < 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
i := f.args
|
||||
i := f.Args
|
||||
for iter := args; iter != nil; iter = iter.Next {
|
||||
i -= 1
|
||||
}
|
||||
|
|
@ -55,13 +55,13 @@ func (f Function) ParseFunction(args *Token) bool {
|
|||
func (f Function) CallFunction(args *Token, vt VarTable, ft FuncTable) *Token {
|
||||
if !f.ParseFunction(args) {
|
||||
log.Log(log.ERR,
|
||||
"Couldnt call " + f.name,
|
||||
"Couldnt call " + f.Name,
|
||||
"eval")
|
||||
return nil
|
||||
}
|
||||
|
||||
f.timesCalled += 1
|
||||
return f.function(args, vt, ft)
|
||||
f.TimesCalled += 1
|
||||
return f.Function(args, vt, ft)
|
||||
}
|
||||
|
||||
func (table FuncTable) GetFunction(arg string) *Function {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue