Refactor yaze initialization and shutdown to use status codes and add error messaging
This commit is contained in:
12
incl/yaze.h
12
incl/yaze.h
@@ -18,11 +18,19 @@ typedef struct yaze_project yaze_project;
|
|||||||
typedef struct yaze_editor_context {
|
typedef struct yaze_editor_context {
|
||||||
z3_rom* rom;
|
z3_rom* rom;
|
||||||
yaze_project* project;
|
yaze_project* project;
|
||||||
|
const char* error_message;
|
||||||
} yaze_editor_context;
|
} yaze_editor_context;
|
||||||
|
|
||||||
|
typedef enum yaze_status {
|
||||||
|
YAZE_UNKNOWN = -1,
|
||||||
|
YAZE_OK = 0,
|
||||||
|
YAZE_ERROR = 1,
|
||||||
|
} yaze_status;
|
||||||
|
|
||||||
void yaze_check_version(const char* version);
|
void yaze_check_version(const char* version);
|
||||||
int yaze_init(yaze_editor_context*);
|
|
||||||
void yaze_cleanup(yaze_editor_context*);
|
yaze_status yaze_init(yaze_editor_context*);
|
||||||
|
yaze_status yaze_shutdown(yaze_editor_context*);
|
||||||
|
|
||||||
struct yaze_project {
|
struct yaze_project {
|
||||||
const char* name;
|
const char* name;
|
||||||
|
|||||||
13
src/yaze.cc
13
src/yaze.cc
@@ -22,23 +22,26 @@ void yaze_check_version(const char *version) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int yaze_init(yaze_editor_context *yaze_ctx) {
|
yaze_status yaze_init(yaze_editor_context *yaze_ctx) {
|
||||||
if (yaze_ctx->project->rom_filename == nullptr) {
|
if (yaze_ctx->project->rom_filename == nullptr) {
|
||||||
return -1;
|
yaze_ctx->error_message = "ROM filename is null";
|
||||||
|
return yaze_status::YAZE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
yaze_ctx->rom = yaze_load_rom(yaze_ctx->project->rom_filename);
|
yaze_ctx->rom = yaze_load_rom(yaze_ctx->project->rom_filename);
|
||||||
if (yaze_ctx->rom == nullptr) {
|
if (yaze_ctx->rom == nullptr) {
|
||||||
return -1;
|
yaze_ctx->error_message = "Failed to load ROM";
|
||||||
|
return yaze_status::YAZE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return yaze_status::YAZE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void yaze_cleanup(yaze_editor_context *yaze_ctx) {
|
yaze_status yaze_shutdown(yaze_editor_context *yaze_ctx) {
|
||||||
if (yaze_ctx->rom) {
|
if (yaze_ctx->rom) {
|
||||||
yaze_unload_rom(yaze_ctx->rom);
|
yaze_unload_rom(yaze_ctx->rom);
|
||||||
}
|
}
|
||||||
|
return yaze_status::YAZE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
yaze_project yaze_load_project(const char *filename) {
|
yaze_project yaze_load_project(const char *filename) {
|
||||||
|
|||||||
Reference in New Issue
Block a user