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