WriteFunction(id, func[, txtmode, nobrk])
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.
True
to write the function in base64 notation or
False
to write plain binary data (defaults to False
)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)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 11The 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.