Skip to content

0riginaln0/odin-partcl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

partcl-odin

Odin bindings for the ParTcl - a micro Tcl implementation.

References:

  • The post of the ParTcl author.

Tutorial

  1. Compile tcl.c into static library:
cd tcl
gcc -c -std=c99 -O3 tcl.c -o tcl.o && ar rcs libpartcl.a tcl.o

MINGW64 shell was used to compile the ParTcl on Windows.

  1. Use it
package main

import "base:runtime"
import "core:fmt"
import "partcl"

main :: proc() {
	ctx: partcl.Tcl

	partcl.init(&ctx)
	defer partcl.destroy(&ctx)

	partcl.register(&ctx, "custom_command", custom_command, 1, nil)

	script: cstring = `custom_command; set x 4; puts [+ [* $x 10] 2];`
	result := partcl.eval(&ctx, script, len(script))

	if result != .FERROR {
		result_str := partcl.to_string(ctx.result)
		result_len := partcl.length(ctx.result)
		fmt.println(string(result_str), result_len)
		fmt.println(partcl.int(ctx.result))
	} else {
		fmt.println("Error evaluating script")
	}
}

custom_command :: proc "c" (tcl: ^partcl.Tcl, args: partcl.Value, arg: rawptr) -> partcl.Control_Flow {
	context = runtime.default_context()
	fmt.println("Custom command called!")
	return .FNORMAL
}
  1. More or less full ParTcl overview main.odin.

  2. Reference REPL implementation repl.odin. Has more native commands registration examples.

> odin run repl
$ rlwrap odin run repl

About

Odin bindings for ParTcl

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors