summaryrefslogtreecommitdiff
path: root/kon/konscript.h
diff options
context:
space:
mode:
authorKonAki <konaki@anokonaki.org>2026-10-13 10:12:33 +0800
committerKonAki <konaki@anokonaki.org>2026-10-13 10:12:33 +0800
commit7a37a5b555cc82d6aaa40997c5f54bc90a31cbc7 (patch)
treebfc5190679252533657a0bcaa00eca5a3b6faeed /kon/konscript.h
parent41a2d1b804118ed4be7ba3f63c56387dca084af3 (diff)
script: read scripts from text with labels
Diffstat (limited to 'kon/konscript.h')
-rw-r--r--kon/konscript.h57
1 files changed, 57 insertions, 0 deletions
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 */