Variable trigger example

Ano script supports running variable trigger function when variable value changes, here is small demonstration about that.

Compilation

Easiest way to get this example running is to go to examples directory in package root, and run:

$ ./build.sh var_trigger

build.sh script compiles Ano script to C, copies source files in place and pops up instructions what to do next. Follow them. Check also examples/README for more info.

Preview

; ------------------------------------------------------------------------------
; var_trigger.ano
;
; To compile:
;
; $ ./build/ano ./examples/var_trigger/var_trigger.ano > \
;     engine/dsl_ano.h
; ------------------------------------------------------------------------------
;
@ANO_SCRIPT_NAME		var_trigger
@ANO_SCRIPT_VERSION		0.0.1
@ANO_SCRIPT_DESCRIPTION	Simple variable trigger example
;
@ANO_FLAGS_USE_PROTOS		[ ]
@ANO_FLAGS_VAR_NAME_SUBS	[ ]
@ANO_FLAGS_VAR_WARN_UNUSED	[ ]
;
; Copyright © 2016-2026, Jani Salonen <salojan@goto10.co>
; All rights reserved.
;
; Ano script supports variable trigger functions when variable value changes,
; here is small demonstration about that.
;

main [exit: 0] {
	print "Trigger:\n\n";

	; Move something to my_one to start trigger function…
	;
	mov my_one (1)

	; …disable trigger temporarily…
	;
	attr_tag ("my_one", "trigger_disable=yes")

	mov my_one (2)

	attr_tag ("my_one", "trigger_disable=no")

	; …and make move again.
	;
	add my_one (3)

	; Make another round with threaded trigger.
	;
	print "\nThreaded trigger:\n\n";

	for (mov _i (0); _i < 10; inc _i) {
		mov my_two (_i)
	}

	; Wait for all trigger threads to finish.
	;
	thread_wait_all
}

trigger my_one {
	fetch _tmp (my_one)

	print "This is trigger for my_one variable, localized as _tmp.\n"
	print "_tmp value is " . _tmp . "\n"
}

trigger my_two [mode: threaded] {
	fetch _tmp (my_two)

	print "This is trigger for my_two variable, localized as _tmp.\n"
	print "_tmp value is " . _tmp . "\n"
}
; ------------------------------------------------------------------------------
; var_trigger.w2c
;
; To compile:
;
; $ ./build/widget ./examples/var_trigger/var_trigger.w2c > \
;     engine/widget_defs.h
; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------
; var_trigger.m2c
;
; To compile:
;
; $ ./build/menu ./examples/var_trigger/var_trigger.m2c > \
;     engine/menu_defs.h
; ------------------------------------------------------------------------------

Copyright © 2026, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.