summaryrefslogtreecommitdiffstats
path: root/DTCallbackScopedVars.c
diff options
context:
space:
mode:
Diffstat (limited to 'DTCallbackScopedVars.c')
-rw-r--r--DTCallbackScopedVars.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/DTCallbackScopedVars.c b/DTCallbackScopedVars.c
new file mode 100644
index 0000000..75eb5e2
--- /dev/null
+++ b/DTCallbackScopedVars.c
@@ -0,0 +1,55 @@
+#strict 2
+
+static const ScopedVar_Callback = 4;
+
+global func CallbackVar(callback) { return [ScopedVar_Callback, callback]; }
+
+global func &CustomScopedVar(array variable)
+{
+ if(variable[0] == ScopedVar_Callback)
+ {
+ return CallA(variable[1], []);
+ }
+ else
+ {
+ return _inherited(variable, ...);
+ }
+}
+
+static const BindCallback_Bind_ScopedVar = -6;
+
+global func Bind_Var(array scopedVar) { return [BindCallback_Bind_ScopedVar, scopedVar]; }
+
+global func BindCustomArgs(array bind, array args, bool safe)
+{
+ if(bind[0] == BindCallback_Bind_ScopedVar)
+ {
+ return ScopedVar(bind[1]);
+ }
+ else
+ {
+ return _inherited(bind, args, safe, ...);
+ }
+}
+
+global func CheckCustomScopedVar(array variable)
+{
+ if(GetType(variable) == C4V_Array && variable[0] == ScopedVar_Callback && GetLength(variable) == 2)
+ {
+ if(CheckCallback(variable[1]))
+ {
+ return true;
+ }
+ }
+
+ return _inherited(variable, ...);
+}
+
+global func CheckBindCallbackCustomBinding(binding)
+{
+ if(GetType(binding) == C4V_Array && GetLength(binding) == 2 && binding[0] == BindCallback_Bind_ScopedVar && CheckScopedVar(binding[1]))
+ {
+ return true;
+ }
+ return _inherited(binding, ...);
+}