aboutsummaryrefslogtreecommitdiff
path: root/nerv/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'nerv/common.h')
-rw-r--r--nerv/common.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/nerv/common.h b/nerv/common.h
index 6657dc4..413ca51 100644
--- a/nerv/common.h
+++ b/nerv/common.h
@@ -7,6 +7,50 @@
#include <stdio.h>
#include <stdlib.h>
+enum {
+ MAT_NORMAL,
+ MAT_GENERAL_ERR,
+ MAT_INSUF_MEM,
+ MAT_INVALID_FORMAT,
+ MAT_WRITE_ERROR,
+ MAT_INVALID_COPY_INTERVAL,
+ MAT_MISMATCH_DIM,
+ MAT_WRONG_MULT_DIM,
+ MAT_ROW_VECTOR_EXP,
+ MAT_COL_VECTOR_EXP,
+ MAT_IDX_VECTOR_EXP,
+ MAT_INVALID_IDX,
+ MAT_CUDA_ERR,
+ MAT_CUBLAS_ERR
+};
+
+typedef struct Status {
+ int err_code;
+ const char *file;
+ int lineno;
+ const char *msg;
+} Status;
+
+#define NERV_SET_STATUS(status, code, m) \
+ do { \
+ (status)->err_code = code; \
+ (status)->msg = m; \
+ (status)->file = __FILE__; \
+ (status)->lineno = __LINE__; \
+ } while (0)
+
+#define NERV_EXIT_STATUS(status, code, msg) \
+ do { \
+ NERV_SET_STATUS(status, code, msg); \
+ return; \
+ } while (0)
+
+#define NERV_LUA_CHECK_STATUS(L, status) \
+ do { \
+ if (status.err_code != MAT_NORMAL) \
+ nerv_error_status(L, &status); \
+ } while (0)
+
typedef struct HashNode {
const char *key;
void *val;
@@ -31,6 +75,7 @@ void hashmap_clear(HashMap *h);
size_t bkdr_hash(const char *key);
int nerv_error(lua_State *L, const char *err_mesg_fmt, ...);
+int nerv_error_status(lua_State *L, Status *status);
int nerv_error_method_not_implemented(lua_State *L);
void luaN_append_methods(lua_State *L, const luaL_Reg *mlist);
#endif