gagent/pkg/picol
James Wells 1bcc682b7c
refactor: converted int64 to int32 where appropriate.
refactor: reduced usage of fmt in favor of logs and string concatication.

refactor: minor re-ordering of the data structures to reduce storage space required.
2023-03-21 07:34:10 -07:00
..
examples [CI SKIP] Refactored project layout per Mark Wolfe Blog : https://www.wolfe.id.au/2020/03/10/how-do-i-structure-my-go-project/ 2021-09-21 07:08:52 -07:00
picol_unused refactor: converted int64 to int32 where appropriate. 2023-03-21 07:34:10 -07:00
commands.go refactor: converted int64 to int32 where appropriate. 2023-03-21 07:34:10 -07:00
parser.go refactor: converted int64 to int32 where appropriate. 2023-03-21 07:34:10 -07:00
picol.go refactor: cleaning up some old issues and stndardizing. 2023-03-20 16:00:15 -07:00
README.md [CI SKIP] Refactored project layout per Mark Wolfe Blog : https://www.wolfe.id.au/2020/03/10/how-do-i-structure-my-go-project/ 2021-09-21 07:08:52 -07:00

picol.go

Original http://oldblog.antirez.com/post/picol.html

Sample use:

func CommandPuts(i *picol.Interp, argv []string, pd interface{}) (string, error) {
	if len(argv) != 2 {
		return "", fmt.Errorf("Wrong number of args for %s %s", argv[0], argv)
	}
	fmt.Println(argv[1])
	return "", nil
}
...
	interp := picol.InitInterp()
	// add core functions
	interp.RegisterCoreCommands()
	// add user function
	interp.RegisterCommand("puts", CommandPuts, nil)
	// eval
	result, err := interp.Eval(string(buf))
	if err != nil {
		fmt.Println("ERROR", err, result)
	} else {
		fmt.Println(result)
	}