]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/iolib.h
Removal of PLIB/SG from SimGear
[simgear.git] / simgear / nasal / iolib.h
1 #ifndef _IOLIB_H
2 #define _IOLIB_H
3
4 #include "nasal.h"
5
6 // Note use of 32 bit ints, should fix at some point to use
7 // platform-dependent fpos_t/size_t or just punt and use int64_t
8 // everywhere...
9
10 // The naContext is passed in for error reporting via
11 // naRuntimeError().
12 struct naIOType {
13     void (*close)(naContext c, void* f);
14     int  (*read) (naContext c, void* f, char* buf, unsigned int len);
15     int  (*write)(naContext c, void* f, char* buf, unsigned int len);
16     void (*seek) (naContext c, void* f, unsigned int off, int whence);
17     int  (*tell) (naContext c, void* f);
18     void (*flush) (naContext c, void* f);
19     void (*destroy)(void* f);
20 };
21
22 struct naIOGhost {
23     struct naIOType* type;
24     void* handle; // descriptor, FILE*, HANDLE, etc...
25 };
26
27 extern naGhostType naIOGhostType;
28 extern struct naIOType naStdIOType;
29
30 #define IOGHOST(r) ((struct naIOGhost*)naGhost_ptr(r))
31 #define IS_IO(r) (IS_GHOST(r) && naGhost_type(r) == &naIOGhostType)
32 #define IS_STDIO(r) (IS_IO(r) && (IOGHOST(r)->type == &naStdIOType))
33
34 // Defined in iolib.c, there is no "library" header to put this in
35 naRef naIOGhost(naContext c, FILE* f);
36
37 #endif // _IOLIB_H