]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/iolib.h
Modified Files:
[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 (*destroy)(void* f);
19 };
20
21 struct naIOGhost {
22     struct naIOType* type;
23     void* handle; // descriptor, FILE*, HANDLE, etc...
24 };
25
26 extern naGhostType naIOGhostType;
27 extern struct naIOType naStdIOType;
28
29 #define IOGHOST(r) ((struct naIOGhost*)naGhost_ptr(r))
30 #define IS_IO(r) (IS_GHOST(r) && naGhost_type(r) == &naIOGhostType)
31 #define IS_STDIO(r) (IS_IO(r) && (IOGHOST(r)->type == &naStdIOType))
32
33 // Defined in iolib.c, there is no "library" header to put this in
34 naRef naIOGhost(naContext c, FILE* f);
35
36 #endif // _IOLIB_H