|
A Code Snippet |
Top Previous Next |
Here is a small code snippet illustrating the process of getting and releasing file numbers. We sacrificed robustness for simplicity, so don't take the code below for a shining example of fd. object's usage. Just see the parts related to the FILENUM library -- that's the point right now.
... 'set "#define FILENUM_MAX_SIGNATURE_LEN 3" and "#define FILENUM_DEBUG_PRINT 1" before running this test
'prepare the disk and create a file fd.format(fd.availableflashspace,16) fd.mount() fd.create("log.txt")
'get a file number... log_filenum=filenum_get("LOG") if log_filenum=255 then sys.halt '...uh-uh, out of sockets! end if
'add data to the file, then close fd.filenum=log_filenum fd.open("LOG") fd.setdata(filenum_who_uses(log_filenum)) fd.close
'release the file number filenum_release(log_filenum) ...
|
And here is what appeared in the output pane of TIDE as the code executed:
FILENUM> 'LOG' got file #0 FILENUM> 'LOG' released file #0
|
The first message corresponds to filenum_get(), the second one -- to filenum_release(). "LOG" is the signature left by us, because this code deals with a log file.
Notice that the data saved into the log file consists of the file number's signature. As a result, the file will contain the string "LOG".