diff options
| author | Herwin Weststrate <[email protected]> | 2016-11-27 09:50:30 +0100 |
|---|---|---|
| committer | Herwin Weststrate <[email protected]> | 2016-11-27 09:50:30 +0100 |
| commit | afee618c1bc25ca798863e07143e24a987758411 (patch) | |
| tree | b22d9a2bc7bf17df093b6d85242230b27c6e7309 /include | |
| parent | 72915cab5228d62cd54c13cdb08fc19587e32865 (diff) | |
| download | mruby-afee618c1bc25ca798863e07143e24a987758411.tar.gz mruby-afee618c1bc25ca798863e07143e24a987758411.zip | |
Added documentation on function for globals
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby/variable.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/include/mruby/variable.h b/include/mruby/variable.h index 15068039a..8b1cc2eef 100644 --- a/include/mruby/variable.h +++ b/include/mruby/variable.h @@ -54,9 +54,67 @@ MRB_API mrb_bool mrb_iv_defined(mrb_state*, mrb_value, mrb_sym); MRB_API mrb_value mrb_iv_remove(mrb_state *mrb, mrb_value obj, mrb_sym sym); MRB_API void mrb_iv_copy(mrb_state *mrb, mrb_value dst, mrb_value src); MRB_API mrb_bool mrb_const_defined_at(mrb_state *mrb, mrb_value mod, mrb_sym id); + +/** + * Get a global variable. Will return nil if the var does not exist + * + * Example: + * + * !!!ruby + * # Ruby style + * var = $value + * + * !!!c + * // C style + * mrb_sym sym = mrb_intern_cstr(mrb, "$value"); + * mrb_value var = mrb_gv_get(mrb, sym); + * + * @param mrb The mruby state reference + * @param sym The name of the global variable + * @return The value of that global variable. May be nil + */ MRB_API mrb_value mrb_gv_get(mrb_state *mrb, mrb_sym sym); + +/** + * Set a global variable + * + * Example: + * + * !!!ruby + * # Ruby style + * $value = "foo" + * + * !!!c + * // C style + * mrb_sym sym = mrb_intern_cstr(mrb, "$value"); + * mrb_gv_set(mrb, sym, mrb_str_new_cstr("foo")); + * + * @param mrb The mruby state reference + * @param sym The name of the global variable + * @param val The value of the global variable + */ MRB_API void mrb_gv_set(mrb_state *mrb, mrb_sym sym, mrb_value val); + +/** + * Remove a global variable. + * + * Example: + * + * !!!ruby + * # Ruby style + * $value = nil + * + * !!!c + * // C style + * mrb_sym sym = mrb_intern_cstr(mrb, "$value"); + * mrb_gv_remove(mrb, sym); + * + * @param mrb The mruby state reference + * @param sym The name of the global variable + * @param val The value of the global variable + */ MRB_API void mrb_gv_remove(mrb_state *mrb, mrb_sym sym); + MRB_API mrb_value mrb_cv_get(mrb_state *mrb, mrb_value mod, mrb_sym sym); MRB_API void mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v); MRB_API void mrb_cv_set(mrb_state *mrb, mrb_value mod, mrb_sym sym, mrb_value v); |
