-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modules/system: Split helpers header into smaller bits
There is a very good reason for this, I think...
- Loading branch information
1 parent
9b8033a
commit eafea43
Showing
7 changed files
with
69 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,9 @@ | ||
#ifndef MOON_MRB_HELPERS | ||
#define MOON_MRB_HELPERS | ||
|
||
#include <mruby.h> | ||
#include <mruby/data.h> | ||
#include <mruby/string.h> | ||
#include <mruby/variable.h> | ||
#include "moon/mrb/helpers/class.hxx" | ||
#include "moon/mrb/helpers/variable.hxx" | ||
#include "moon/mrb/helpers/error.hxx" | ||
#include "moon/mrb/helpers/data.hxx" | ||
|
||
#define IVget(_name_) mrb_iv_get(mrb, self, mrb_intern_lit(mrb, _name_)) | ||
#define IVset(_name_, _value_) mrb_iv_set(mrb, self, mrb_intern_lit(mrb, _name_), _value_) | ||
|
||
#define KEY_SHADER "@shader" | ||
#define KEY_VBO "@vbo" | ||
#define KEY_ORIGIN "@origin" | ||
|
||
#define MOON_GET_CLASS(__name__) mrb_class_get_under(mrb, mrb_module_get(mrb, "Moon"), __name__) | ||
#define MOON_GET_MODULE(__name__) mrb_module_get_under(mrb, mrb_module_get(mrb, "Moon"), __name__) | ||
; | ||
|
||
static inline mrb_value | ||
moon_iv_get(mrb_state *mrb, mrb_value self, const char *name) | ||
{ | ||
mrb_value iv_value = mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, name)); | ||
if (mrb_nil_p(iv_value)) { | ||
mrb_raisef(mrb, E_ARGUMENT_ERROR, "Cannot use a nil %S", mrb_str_new_cstr(mrb, name)); | ||
} | ||
return iv_value; | ||
} | ||
|
||
static inline void | ||
moon_data_cleanup(mrb_state *mrb, mrb_value self) | ||
{ | ||
void *ptr = DATA_PTR(self); | ||
const struct mrb_data_type* type = DATA_TYPE(self); | ||
if (ptr && type) { | ||
type->dfree(mrb, ptr); | ||
} | ||
DATA_PTR(self) = NULL; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef MOON_MRB_CLASS_HELPERS | ||
#define MOON_MRB_CLASS_HELPERS | ||
|
||
#include <mruby.h> | ||
#include <mruby/class.h> | ||
|
||
#define MOON_GET_CLASS(__name__) mrb_class_get_under(mrb, mrb_module_get(mrb, "Moon"), __name__) | ||
#define MOON_GET_MODULE(__name__) mrb_module_get_under(mrb, mrb_module_get(mrb, "Moon"), __name__) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef MOON_MRB_DATA_HELPERS | ||
#define MOON_MRB_DATA_HELPERS | ||
|
||
#include <mruby.h> | ||
#include <mruby/data.h> | ||
|
||
static inline void | ||
moon_data_cleanup(mrb_state* mrb, mrb_value self) | ||
{ | ||
void *ptr = DATA_PTR(self); | ||
const struct mrb_data_type* type = DATA_TYPE(self); | ||
if (ptr && type) { | ||
type->dfree(mrb, ptr); | ||
} | ||
DATA_PTR(self) = NULL; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef MOON_MRB_ERROR_HELPERS | ||
#define MOON_MRB_ERROR_HELPERS | ||
|
||
#include "moon/mrb/helpers/class.hxx" | ||
|
||
#define MOON_E_FILE_NOT_FOUND MOON_GET_CLASS("FileNotFoundError") | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef MOON_MRB_VARIABLE_HELPERS | ||
#define MOON_MRB_VARIABLE_HELPERS | ||
|
||
#include <mruby.h> | ||
#include <mruby/variable.h> | ||
#include <mruby/string.h> | ||
|
||
#define IVget(_name_) mrb_iv_get(mrb, self, mrb_intern_lit(mrb, _name_)) | ||
#define IVset(_name_, _value_) mrb_iv_set(mrb, self, mrb_intern_lit(mrb, _name_), _value_) | ||
|
||
static inline mrb_value | ||
moon_iv_get(mrb_state* mrb, mrb_value self, const char* name) | ||
{ | ||
mrb_value iv_value = mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, name)); | ||
if (mrb_nil_p(iv_value)) { | ||
mrb_raisef(mrb, E_ARGUMENT_ERROR, "Cannot use a nil %S", mrb_str_new_cstr(mrb, name)); | ||
} | ||
return iv_value; | ||
} | ||
|
||
#define KEY_VBO "@vbo" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Moon | ||
# Error raised when a resource cannot be found on disk | ||
class FileNotFoundError < RuntimeError | ||
end | ||
end |