much stdlib docs

This commit is contained in:
Aidan 2020-07-19 14:37:20 -07:00
parent b941df68e1
commit ee39de01fd
No known key found for this signature in database
GPG key ID: 327711E983899316
9 changed files with 228 additions and 74 deletions

View file

@ -24,7 +24,11 @@ import (
"gitlab.com/whom/shs/log"
)
func concat(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
/* Concatenates N stringables
*
* Example: (concat "hello" " " "world")
*/
func Concat(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
in = in.Eval(ft, vt, false)
var res string
@ -43,14 +47,25 @@ func concat(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
return t
}
func str_cast(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
/* Takes 1 argument, returns its value as a string
* works on lists too.
*
* Example: (string 1) -> 1.0
*/
func StrCast(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
body := in.Eval(ft, vt, false).String()
res := &ast.Token{ Tag: ast.STRING }
res.Set(body)
return res
}
func print_str(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
/* Takes one arg, returns nil
* Prints a string to stdout
* Unquotes string so user can add escaped chars like \n, \t, etc
*
* Example: (print "Line: \n, Tab: \t")
*/
func PrintStr(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
body := in.Eval(ft, vt, false).String()
if body[0] != body[len(body)-1] && body[0] != '"' {
body = "`" + body + "`"