From 7a37a5b555cc82d6aaa40997c5f54bc90a31cbc7 Mon Sep 17 00:00:00 2001 From: KonAki Date: Tue, 13 Oct 2026 10:12:33 +0800 Subject: script: read scripts from text with labels --- kon/konscript.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'kon/konscript.h') diff --git a/kon/konscript.h b/kon/konscript.h index 8b5a024..726768d 100644 --- a/kon/konscript.h +++ b/kon/konscript.h @@ -131,4 +131,61 @@ int32_t kon_scriptVar(const kon_script_t *vm, int id); void kon_scriptSetSwitch(kon_script_t *vm, int id, int on); void kon_scriptSetVar(kon_script_t *vm, int id, int32_t value); +/*** text scripts ***/ + +/* the same commands as text, so a script can be written, read and changed by hand and a converter can write one. +one command a line, # starts a comment, labels are names to jump to: + + start: + say ada "Morning." + host enter 0 1 + menu + option "Sorry." sorry + option "About the key..." key if s0 + sorry: + set v1 = 0 + if v1 < 2 else done + jump start + done: + end + +say who "text" | menu | option "text" label [if sN] | jump label | call label | return | end | wait ms +on sN | off sN | flip sN | set vN (= += -= *= /= %=) number-or-vM +if sN on|off else label | if vN (== != >= <= > <) number-or-vM else label +host name-or-number [b [c [d]]] ["text"] + +who and the host name are numbers, or names from the lists you give. use - for nobody. in strings, \" \\ \n and \t work */ + +#define KON_SCRIPT_LABEL 32 + +typedef struct kon_scriptLabel { + char name[KON_SCRIPT_LABEL]; + int at; +} kon_scriptLabel_t; + +typedef struct kon_scriptNames { + const char *const *speakers; + int speakerCount; + const char *const *hosts; + int hostCount; +} kon_scriptNames_t; + +typedef struct kon_scriptBuild { + const kon_scriptNames_t *names; /* can be NULL */ + kon_cmd_t *cmds; + int maxCmds; + char *pool; /* where the strings go, the commands point into it so keep it as long as them */ + int poolSize; + kon_scriptLabel_t *labels; + int maxLabels; + + int count, labelCount, poolUsed; /* what it made */ + int errorLine; /* 0 if no error */ + char error[64]; +} kon_scriptBuild_t; + +/* 1 if it worked, 0 and errorLine, error if not */ +int kon_scriptParse(kon_scriptBuild_t *b, const char *source); +int kon_scriptFind(const kon_scriptBuild_t *b, const char *label); /* where a label is, or -1 */ + #endif /* KONSCRIPT_H */ -- cgit