This context enables the WebDNA programmer to call a previously defined block of WebDNA code.
[function] This context enables the WebDNA programmer to call a previously defined block of WebDNA code. Functions allow you to create your own tags to use just as you would any other predefined WebDNA tag. A function will override a native WebDNA tag, so you could, for instance, redefine the date and time tags to match a different time zone, if your server is not local to you. A function is a handy way to perform a complicated series of instructions so you need only maintain one piece of code, but use it a number of times in your page.[function name=citytime]
[format seconds_to_time %I:%M %p][math]{[time]}+{[more]:00:00}-{[less]:00:00}[/math][/format]
[/function]
<b>Current time around the world</b>
[citytime more=0&less=0] - New York City<br>
[citytime more=0&less=3] - Seattle<br>
[citytime more=7&less=0] - Paris
name | User defined name for the function. The name is then used like any other WebDNA tag, as in our example. |
preparse | T/F Optional. By default, the WebDNA code that makes up the function is stored 'raw' and executed later when the function is called, as in our citytime example above, because the variables are, well, variable. But if you need to use WebDNA to create the function in the first place, then you can set 'preparse' to 'T'. This will force the WebDNA engine to first parse the WebDNA in the function definition before storing it for later use. Usage: [function name=somename&preparse=t] |
[function name=Backwards]
[text]length=[countchars][instring][/countchars][/text]
[loop start=[length]&end=1&advance=-1][getchars start=[index]&end=[index]][instring][/getchars][/loop]
[/function]
[Backwards instring=abcdef_12345]
[!] ** create primary numbers function ** [/!]
[function name=PrimeNums]
[return]2,3,5,7,11,13,17,19,23,29[/return][/function]
[!] ** Display primary numbers function ** [/!]
[PrimeNums]
[!] ** create primary numbers function ** [/!]
[!] ** adding a param called fmode ** [/!]
[function name=PrimeNums]
[!] ** table of primes (could be a .db file, or MySQL database as well) ** [/!]
[table name=primes&fields=pnum]
2
3
5
7
11
13
17
19
23
29
[/table]
[switch value=[fmode]]
[case value=random]
[search table=primes&[!]
[/!]nePNUMdatarq=find_all&[!]
[/!]raPNUMsort=1&[!]
[/!]PNUMtype=num[!]
[/!]&max=1]
[return][founditems][PNUM][/founditems][/return]
[/search]
[/case]
[default]
[!] ** find all primes ** [/!]
[search table=primes&nePNUMdatarq=find_all]
[return][founditems][PNUM],[/founditems][/return]
[/search]
[/default]
[/switch]
[/function]
[!] ** Find all Prime Numbers ** [/!]
[PrimeNums]
[!] ** Find a random prime number ** [/!]
[PrimeNums fmode=random]
if you use a custom suffix such as "dnalib", you should add this mapping within your WebDNA prefs so that WebDNA knows to process this file type. First, find your "WebCatalogEngine" directory and edit the file "webdna.conf" so that "dnalib" is added along with all the other mappings (towards the end of the file). Then, in your admin prefs, add .dnalib as an allowable suffix. (you can avoid the extra mapping stuff by using ".inc"
[!] ** donovan's sample library **
** File: mylibrary.inc **
** created Mar 23 2009 **
** function prefix convention "ml_"
[/!][!]
** NAME: "ml_list"
** DESCRIPTION: Returns a list of available functions in this library **
** INPUT: none
** OUTPUT: List of function names
[/!][function name=ml_list]
[return]Ml_List,Ml_PrimNums[/return]
[/function][!]
** NAME: "ML_PrimeNums"
** DESCRIPTION: Library for dealing with Prime Numbers **
** INPUT: "fmode"
params:
"random"
(leave blank to find all prime numbers)
** OUTPUT: Prime Numbers
[/!][function name=Ml_PrimeNums]
[!] ** table of primes (could be a .db file, or MySQL database as well) ** [/!]
[table name=primes&fields=pnum]
2
3
5
7
11
13
17
19
23
29
[/table]
[switch value=[fmode]]
[case value=random]
[search table=primes&[!]
[/!]nePNUMdatarq=find_all&[!]
[/!]raPNUMsort=1&[!]
[/!]PNUMtype=num[!]
[/!]&max=1]
[return][founditems][PNUM][/founditems][/return]
[/search]
[/case]
[default]
[!] ** find all primes ** [/!]
[search table=primes&nePNUMdatarq=find_all]
[return][founditems][PNUM],[/founditems][/return]
[/search]
[/default]
[/switch]
[/function]
[include file=mylibrary.inc]
With the module version of WebDNA, the Globals directory is in your "WebCatalogEngine" directory.. however, if you want access to your library from within a WebDNA Sandbox, you will have to find the "Globals" directory for that particular sandbox. By default, this would be "WebCatalogEngine/SandBoxes/
[!] List of available functions in mylibrary.inc [/!]
[Ml_list]
[!] List all prime numbers [/!]
[Ml_PrimeNums]
DOWNLOAD WEBDNA NOW!
A list of the currently available modules...
AWS Raw WebDNA LAMP-Plus WebServerAmazon Web Services (AWS) README for Machine Image ID...
WebDNA LibrariesA list of available libraries for WebDNA...
[biotype]BioType is a behavioral biometrics WebDNA function based on ADGS research and development (from version 8...
Technical Change HistoryThis Technical Change History provides a reverse chronological list of WebDNA changes...
Download WebDNA ApplicationsWebDNA applications...
[founditems]...
[object]Embeds the results of an external function...
[fileinfo]Displays information about a particular file or folder...
[convertwords]Changes specified words in a string of text to different words...
[delete][delete db=some...
[tcpsend]A powerful feature that sends text to a TCP server program on a remote machine...