mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-18 21:11:03 +01:00
added
This commit is contained in:
43
vendor/github.com/glycerine/zygomys/zygo/msgpackmap.go
generated
vendored
Normal file
43
vendor/github.com/glycerine/zygomys/zygo/msgpackmap.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
package zygo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (env *Zlisp) ImportMsgpackMap() {
|
||||
env.AddMacro("msgpack-map", MsgpackMapMacro)
|
||||
env.AddFunction("declare-msgpack-map", DeclareMsgpackMapFunction)
|
||||
}
|
||||
|
||||
// declare a new record type
|
||||
func MsgpackMapMacro(env *Zlisp, name string,
|
||||
args []Sexp) (Sexp, error) {
|
||||
|
||||
if len(args) < 1 {
|
||||
return SexpNull, fmt.Errorf("struct-name is missing. use: " +
|
||||
"(msgpack-map struct-name)\n")
|
||||
}
|
||||
|
||||
return MakeList([]Sexp{
|
||||
env.MakeSymbol("def"),
|
||||
args[0],
|
||||
MakeList([]Sexp{
|
||||
env.MakeSymbol("quote"),
|
||||
env.MakeSymbol("msgmap"),
|
||||
&SexpStr{S: args[0].(*SexpSymbol).name},
|
||||
}),
|
||||
}), nil
|
||||
}
|
||||
|
||||
func DeclareMsgpackMapFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) {
|
||||
if len(args) != 1 {
|
||||
return SexpNull, WrongNargs
|
||||
}
|
||||
|
||||
switch t := args[0].(type) {
|
||||
case *SexpStr:
|
||||
return t, nil
|
||||
}
|
||||
return SexpNull, errors.New("argument must be string: the name of the new msgpack-map constructor function to create")
|
||||
}
|
||||
Reference in New Issue
Block a user