File I/OAvailability LightWave® 6.0 This global provides functions for reading and writing data in files. The state
structures returned by the open functions are the same as those passed to the handler save and load callbacks, making it
possible for handlers to create and read custom preset files with the same code they use
to write and read their settings in scene and object files. This is also an easy way for
any kind of Layout plug-in to create block- Global Call LWFileIOFuncs *fiof; fiof = global( LWFILEIOFUNCS_GLOBAL, GFUSE_TRANSIENT ); The global function returns a pointer to an LWFileIOFuncs. The structure returned by the open functions is described on the file I/O page. typedef struct st_LWFileIOFuncs { LWSaveState * (*openSave) (const char *name, int ioMode); void (*closeSave)(LWSaveState *save); LWLoadState * (*openLoad) (const char *name, int ioMode); void (*closeLoad)(LWLoadState *load); } LWFileIOFuncs;
Example This code fragment creates a text file and writes the contents of a structure. It uses the Observer structure and the write_obs function defined in the Example section of the file I/O page. #include <lwserver.h> #include <lwio.h> LWFileIOFuncs *fiof; LWSaveState *save; Observer obs = { 4.0f, "EDT", 2000, 4, 24, 2, 5, 30, 37.75f, -122.55f, 1, 40.0f, 30.0f, 100.0f, 2000.0f }; fiof = global( LWFILEIOFUNCS_GLOBAL, GFUSE_TRANSIENT ); if ( !fiof ) return AFUNC_BADGLOBAL; if ( save = fiof->openSave( "testio.txt", LWIO_ASCII )) { write_obs( save, &obs ); fiof->closeSave( save ); } if ( save = fiof->openSave( "testio.bin", LWIO_BINARY )) { write_obs( save, &obs ); fiof->closeSave( save ); } |