1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
11 * Native Shelf Abstraction (NAL).
16 #ifndef SQUIRRELJME_NATIVE_H
17 #define SQUIRRELJME_NATIVE_H
19 #include "sjme/stdTypes.h"
20 #include "sjme/error.h"
21 #include "sjme/seekable.h"
25 #ifndef SJME_CXX_IS_EXTERNED
26 #define SJME_CXX_IS_EXTERNED
27 #define SJME_CXX_SQUIRRELJME_NATIVE_H
29 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
30 #endif /* #ifdef __cplusplus */
32 /*--------------------------------------------------------------------------*/
35 * Returns the current time in milliseconds as per the Java
36 * method @c System::currentTimeMillis() .
38 * @param result The resultant time.
39 * @return any resultant error code.
42 typedef sjme_errorCode (*sjme_nal_currentTimeMillisFunc
)(
43 sjme_attrOutNotNull sjme_jlong
* result
)
47 * Opens the given file natively.
49 * @param inPool The pool for allocations.
50 * @param inPath The path to open.
51 * @param outSeekable The seekable to open within.
52 * @return Any resultant error, if any.
55 typedef sjme_errorCode (*sjme_nal_fileOpenFunc
)(
56 sjme_attrInNotNull sjme_alloc_pool
* inPool
,
57 sjme_attrInNotNull sjme_lpcstr inPath
,
58 sjme_attrOutNotNull sjme_seekable
* outSeekable
);
61 * Reads from the system environment a variable.
63 * @param buf The output buffer.
64 * @param bufLen The length of the buffer to store within.
65 * @param env The environment variable to lookup.
66 * @return Any resultant error code. Will return @c SJME_ERROR_NO_SUCH_ELEMENT
67 * if there is no environment variable with the given name.
70 typedef sjme_errorCode (*sjme_nal_getEnvFunc
)(
71 sjme_attrInNotNull
sjme_attrOutNotNullBuf(len
) sjme_lpstr buf
,
72 sjme_attrInPositiveNonZero sjme_jint bufLen
,
73 sjme_attrInNotNull sjme_lpcstr env
)
77 * Returns the current nanosecond monotonic class as per the Java
78 * method @c System::nanoTime() .
80 * @param result The resultant time.
81 * @return Any resultant error code.
84 typedef sjme_errorCode (*sjme_nal_nanoTimeFunc
)(
85 sjme_attrOutNotNull sjme_jlong
* result
)
89 * Formatted text to standard stream.
91 * @param format The format string.
92 * @param ... Format arguments.
93 * @return Any resultant error code.
96 typedef sjme_errorCode (*sjme_nal_stdFFunc
)(
97 sjme_attrInNotNull sjme_lpcstr format
,
101 * Native Abstraction Layer functions.
105 typedef struct sjme_nal
107 /** Current time in milliseconds. */
108 sjme_nal_currentTimeMillisFunc currentTimeMillis
;
110 /** Opens a given native file. */
111 sjme_nal_fileOpenFunc fileOpen
;
113 /** Get environment variable. */
114 sjme_nal_getEnvFunc getEnv
;
116 /** Get the current monotonic nanosecond time. */
117 sjme_nal_nanoTimeFunc nanoTime
;
119 /** Formatted output to standard error. */
120 sjme_nal_stdFFunc stdErrF
;
122 /** Formatted output to standard output. */
123 sjme_nal_stdFFunc stdOutF
;
126 /** Default native abstraction layer. */
127 extern const sjme_nal sjme_nal_default
;
129 #if !defined(SJME_CONFIG_MISSING_ERRNO)
132 * Maps @c errno to a SquirrelJME error.
134 * @param errNum The error number.
135 * @return The resultant error.
138 sjme_errorCode
sjme_nal_errno(sjme_jint errNum
);
143 * Maps @c errno to a SquirrelJME error.
145 * @param errNum The error number.
146 * @return The resultant error.
149 #define sjme_nal_errno(ignored) ((sjme_errorCode)(SJME_ERROR_NATIVE_ERROR))
153 /*--------------------------------------------------------------------------*/
157 #ifdef SJME_CXX_SQUIRRELJME_NATIVE_H
159 #undef SJME_CXX_SQUIRRELJME_NATIVE_H
160 #undef SJME_CXX_IS_EXTERNED
161 #endif /* #ifdef SJME_CXX_SQUIRRELJME_NATIVE_H */
162 #endif /* #ifdef __cplusplus */
164 #endif /* SQUIRRELJME_NATIVE_H */