mojo_client/bin/scripts/__core_func.def
false_genesis 76ebbe5cf3 * rewrote the SCP data storage. note that all database files must now be placed in a directory added with "AddDBPath <path>" and must contain a #dbname tag. the db now converts SCP (text) to SCC (binary) files, which increases access speed a lot. also less RAM used in most cases.
* replaced "LoadSCP" func with "LoadDB <dbname>" (different syntax!); removed all other scp db related funcs except "getscpvalue"
* the GUI can now show texts stored in databases
* added displaying status to SceneLogin
* misc fixes/cleanups
2008-04-19 23:45:37 +00:00

141 lines
4.2 KiB
Modula-2

// core functions. required by other scripts to run!
#onload
log * Loading core scripts...
#/onload
//--------------------------------------------------------
#script=append
//--------------------------------------------------------
// usage: append text to a string.
// args:
// @def: text to append
// @0: variable to which the text should be appended
// get the var name if the original variable
SET,v #${@caller}::${@0}
// if it has not been set before, init it now
DEFAULT,${v}
// append to the original var. inner ${..} gets the var name, outer ${..} get the value of the var name we just got.
SET,${v} ${${v}}${@def}
// remove the name placeholder
UNSET v
//-------------------------------------------------
#script=string_is_command
//-------------------------------------------------
// purpose: detect if @def might be a server command.
// split all chars we have set in the config files to a list.
lsplit,#CMDCHARLIST ${#OTHER_CMD_CHARS}
// find out the first char of the string
SET,c ?{SUBSTR,1 ${@def}}
// does the char list contain our first char? if yes it can trigger a server command.
if ?{lcontains,#CMDCHARLIST ${c}}
unset c
return true
endif
unset c
return false
//--------------------------------------------------------
#script=normalize_name
//--------------------------------------------------------
// uppercases first char, lowercases rest
set,name ?{uppercase ?{substr,1 ${@def}}}
set,len ?{strlen ${@def}}
sub,len 1
append,name ?{lowercase ?{substr,${len},1 ${@def}}}
return ${name}
//---------------------------------------------------------
#script=globname
//---------------------------------------------------------
// purpose: returns the global name of a variable
// args: @def: var name, @0 (optional): name of the intended parent func
set,c ?{substr,1 ${@def}}
// it is a global var if the varname starts with # or there is no caller script
if ?{or,?{equal,# ${c}} ?{not ${@caller}}}
return ${@def}
endif
set,top ${@0}
default,top ${@caller}
return #${top}::${@def}
//---------------------------------------------------------
#script=sclistname
//---------------------------------------------------------
// purpose: returns the global name of a script list
// args: @def: script name
set,c ?{substr,1 ${@def}}
// it is a global name already if the script name starts with # or there is no caller script
if ?{or,?{equal,# ${c}} ?{not ${@caller}}}
return ${@def}
endif
return #DEFSCRIPT::SCRIPT::${@def}
//---------------------------------------------------------
#script=getvar
//---------------------------------------------------------
// purpose: returns the value of a variable. if the variable hasnt been set return empty string.
set,top ${@caller}
default,top #
set,v ?{globname,${top} ${@def}}
unset top
//out getvar: v=${v} -> ${${v}}
if ?{isset ${v}}
return ${${v}}
endif
return
//---------------------------------------------------------
#script=reverse
//---------------------------------------------------------
// purpose: reverse a srtring
// args: @def: string to reverse
// returns: reversed string
set,outstr
set,elems ?{lsplit,mylist ${@def}}
set,i ${elems}
loop
sub,i 1
if ?{equal,${i} -1}
exitloop
endif
append,outstr ?{lindex,mylist ${i}}
endloop
ldelete mylist
return ${outstr}
//--------------------------------------------------------
#script=appenddef
//--------------------------------------------------------
// purpose: append a line of code to a script
// args: @0: script name; @def: code
// be sure that the code you append is valid and working DefScript code! (no if/loop block mismatches, etc)
// if you need to use { or }, escape them: "appenddef,myscript log Myscript: finished, @def=$\{@def\}"
set,sc ?{lowercase ${@0}}
if ?{and,{?{strlen ${@def}}} ?{strlen ${sc}}}
if ?{not ?{ScriptExists ${sc}}}
createdef ${sc}
endif
lpushback,{?{sclistname ${sc}}} ${@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,{?{sclistname ?{lowercase ${@0}}}} ${@def}}