What've you crossed off your to do list today....

Miscellaneous Forums/General Discussion/What've you crossed off your to do list today....


thats neat Sculpture, must try lisp at somepoint - do you use it for BMax, B3D or C IDE?


Actually, I'm just using it for my own lisp project at the moment. While I'm sticking with BMax for any graphical projects that come up, my current project is an online MUD server and Lisp is just more suited to the job. I'm still thinking Blitzmax might be the best choice for the custom client, though!

Regarding the thread topic: this wasn't really on my todo list, per se, but I'm almost ready to cross off "write a binary parsing library in Lisp" as I work through some tutorial code here.

This'll be a handy library. Basically, with the aid of this library, instead of hand-writing functions to define a binary class and define reader and writer functions, all that's needed is something like the following
(define-binary-class id3-tag
  ((file-identifier (iso-8859-1-string :length 3))
   (major-version   u1)
   (revision        u1)
   (flags           u1)
   (size            id3-tag-size)
   (frames          (id3-frames :tag-size size)))) 


which will make a class named id3-tag, with the fields "file-identifier", "major-version", "revision", etc. It will also automatically create a specialized version of the function (read-value) that properly reads in each field based on the declaration above (so file-identifier will be an ISO-8859-1 string of length 3, major-version, revision, and flags will all be unsigned-longs, etc)

So now if I want to read in an id3 tag from a file, all I have to do is go (read-value 'id3-tag input-file) and that function call will return an instance of the Id-3 class with the data fields properly initialized.

Same thing with output. The "(define-binary-class)" macro above automatically generates an output function specialized on the class too. So calling (write-value 'id3-tag output-stream) will write all of the above fields to the binary file.

So now, instead of hand-coding the class definition, the reader function, and the writer function for any binary format, all I have to do is call the (define-binary-class) macro. If I have a custom player object, with the fields named and typed as follows

lives:byte
health:unsigned long
x-coord:short
y-coord:short

I can go
(define-binary-class player
   ((lives (byte)
    (health (ul))
    (x-coord (short))
    (y-coord (short)))


and now the class and reader and writer functions will be generated. After that, a simple call to
(write-value 'player my-player-variable output-file)


and voila, the players binary data is written to the file. Keep in mind, I didn't handcode the functions "write-value" or "read-value" for any of the above examples. They were programatically generated by "define-binary-class".

Any binary data structure can be created, along with it's accompanying reader and writer functions, with a simple and short call to the define-binary-class macro above. (that's because the macro is called prior to compilation, and it looks at the data that is passed to it, and then utilizes that data to automatically define the class and the functions needed. Basically, it's doing some hardcore pre-processor work, although it's relatively easy to write code to do this thanks to the systematic syntax of lisp. So the definition of the player class above, which is only 5 lines long, will end up being converted into about 25-30 lines of lisp code. This all happens prior to compilation, so there is no speed hit.)

This is why Lisp is known as the programmable programming language. :P