diff --git a/bin/scripts/__core_func.def b/bin/scripts/__core_func.def index 2256c79..fe596b4 100644 --- a/bin/scripts/__core_func.def +++ b/bin/scripts/__core_func.def @@ -149,7 +149,17 @@ if ?{and,{?{strlen ${@def}}} ?{strlen ${@0}}} logdebug AppendDef: ${@0} didnt exist, created endif - lpushback,#DEFSCRIPT::SCRIPT::${@0} ${@def} + lpushback,{#DEFSCRIPT::SCRIPT::${@0}} ${@def} unset cmd endif +//--------------------------------------------------------- +#script=scripthasline +//--------------------------------------------------------- +// purpose: check if a script has a certain line of code (exact match) +// args: +// @0: script name +// @def: line of text to look for + +return ?{lcontains,{#DEFSCRIPT::SCRIPT::${@0}} ${@def}} + diff --git a/bin/scripts/example_scriptHook.def b/bin/scripts/example_scriptHook.def new file mode 100644 index 0000000..8d1dd12 --- /dev/null +++ b/bin/scripts/example_scriptHook.def @@ -0,0 +1,56 @@ +//---------------------------------- +#script=hook_example_base +//---------------------------------- +// just do some random stuff here +set,var 0 +set,x hello world +add,var 15 +out base: var=${var} + + + +//---------------------------------- +#script=hook_example_hooker +//---------------------------------- +#onload +set,counter 0 +#/onload + +// check if we have already added our code +if ?{ScriptHasLine,hook_example_base #tag:hook:${@myname}} + out Hook Example: code already added, skipping. +else + set,somevar some text + + // this is a custom "tag" to indicate the modification. its necessary because a 'reloaddef' on base script removes our custom content, + // so we can check if our added lines are still there; and a reloaddef on this script would cause the lines to get added twice or more. + appenddef,hook_example_base #tag:hook:${@myname} + + appenddef,hook_example_base out == this is the hooked part == + appenddef,hook_example_base out text copied from hooking script: ${somevar} + appenddef,hook_example_base out x in base script: $\{x\} + appenddef,hook_example_base out add,a 10 + appenddef,hook_example_base out var=$\{var\} + out Hook Example: ++ code appended. +endif + +// everytine this script gets executed, add the same line of code to a "new" script (its not defined if you call this first time) +appenddef,hook_example_new out line of text [${counter}] +add,counter 1 + + + +//---------------------------------- +#script=hook_example_cleanup +//---------------------------------- +unloaddef hook_example_new +// other possible way: lclear DEFSCRIPT::SCRIPT::hook_example_new + + + +//----------------------------------- +// dummy for running scripts as soon as all scripts in this file are loaded +#script=dummy +#onload +hook_example_hooker +#/onload \ No newline at end of file