Name
WriteFunction -- write a function to a file (V4.0)
Synopsis
WriteFunction(id, func[, txtmode, nobrk])
Function
This function writes the Hollywood function specified by func to the file specified by id at the current file cursor position which you can modify by using the Seek() command. The function will be written to the file as precompiled bytecode, i.e. it will not be human readable.

You can load saved functions into other projects by using the ReadFunction() command. The optional argument txtmode specifies whether or not the function shall be written to the file as binary data or as base64 encoded data. The latter is useful for embedding Hollywood functions in human readable text files, for instance XML files. In case you enable text mode, WriteFunction() will automatically insert a line break after every 72 characters for better readability. If you don't want that, set the optional argument nobrk to True. In that case, no line breaks will be inserted.

Inputs
id
file to write to
func
function to write to the file
txtmode
optional: True to write the function in base64 notation or False to write plain binary data (defaults to False)
nobrk
optional: True if you don't want to have line breaks inserted when in text mode (defaults to False); this argument is ignored in binary mode (V6.1)
Example
Function p_LittleTestFunc(a, b)
  Return(a+b)
EndFunction

OpenFile(1, "func.bin", #MODE_WRITE)
WriteFunction(1, p_LittleTestFunc)
CloseFile(1)

OpenFile(1, "func.bin", #MODE_READ)
p_MyAdd = ReadFunction(1)
CloseFile(1)

Print(p_MyAdd(5, 6))  ; prints 11
The code above writes the function p_LittleTestFunc() to file "func.bin". After that, it opens file "func.bin" again and reads the function back into Hollywood. The imported function will be stored in the variable p_MyAdd(). Finally, we will call the newly imported function p_MyAdd() and it will add the numbers 5 and 6 for us.

Show TOC