gagent/pkg/picol
2023-05-18 18:04:20 -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 feat: added some more test harness. 2023-04-03 19:43:35 -07:00
commands.go feat: added some more test harness. 2023-04-03 19:43:35 -07:00
commands_test.go feat: added some more test harness. 2023-04-03 19:43:35 -07:00
LICENSE.md fix: somehow I list the license, re-adding. 2023-03-31 07:06:28 -07:00
parser.go fix: modified to fix some of the test failures. 2023-05-18 18:04:20 -07:00
parser_test.go fix: modified to fix some of the test failures. 2023-05-18 18:04:20 -07:00
picol.go fix: modified to fix some of the test failures. 2023-05-18 18:04:20 -07:00
picol_test.go feat: added some more test harness. 2023-04-03 19:43:35 -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)
	}