Skip to content

Commit

Permalink
Renamed MrbWrap to Anyolite
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadeweka committed Apr 5, 2021
1 parent 82c28cd commit af742e7
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 111 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Now, you want to wrap this class in Ruby. All you need to do is to execute the f
require "anyolite"
MrbState.create do |mrb|
MrbWrap.wrap(mrb, TestModule)
Anyolite.wrap(mrb, TestModule)
mrb.load_script_from_file("examples/hp_example.rb")
end
Expand Down Expand Up @@ -154,7 +154,7 @@ The term 'anyoli' means 'green' in the Maasai language, thus naming 'anyolite'.

#### Breaking changes

* [ ] Rename `MrbWrap` to `Anyolite`
* [X] Rename `MrbWrap` to `Anyolite`
* [ ] Rename `MrbMacro` to `Anyolite::Macro`
* [ ] Rename `mrb` and `mruby` in the code to `rb` and `ruby`
* [ ] Rework configurations for the Rakefile into a class
Expand Down
2 changes: 1 addition & 1 deletion anyolite.cr
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require "./src/MrbWrap.cr"
require "./src/Main.cr"
26 changes: 13 additions & 13 deletions src/MrbWrap.cr → src/Main.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require "./MrbRefTable.cr"
alias MrbFunc = Proc(MrbInternal::MrbState*, MrbInternal::MrbValue, MrbInternal::MrbValue)

# Main wrapper module, which should be covering most of the use cases.
module MrbWrap
module Anyolite
# Alias for all possible mruby return types.
alias Interpreted = Nil | Bool | MrbInternal::MrbFloat | MrbInternal::MrbInt | String | Undefined

Expand Down Expand Up @@ -219,8 +219,8 @@ module MrbWrap
# The values *operator_getter* and *operator_setter* will append the specified `String`
# to the final names and *context* can give the function a `Path` for resolving types correctly.
macro wrap_property(mrb_state, crystal_class, name, proc, proc_arg, operator_getter = "", operator_setter = "=", context = nil)
MrbWrap.wrap_getter({{mrb_state}}, {{crystal_class}}, {{name}}, {{proc}}, operator: {{operator_getter}}, context: {{context}})
MrbWrap.wrap_setter({{mrb_state}}, {{crystal_class}}, {{name + "="}}, {{proc}}, {{proc_arg}}, operator: {{operator_setter}}, context: {{context}})
Anyolite.wrap_getter({{mrb_state}}, {{crystal_class}}, {{name}}, {{proc}}, operator: {{operator_getter}}, context: {{context}})
Anyolite.wrap_setter({{mrb_state}}, {{crystal_class}}, {{name + "="}}, {{proc}}, {{proc_arg}}, operator: {{operator_setter}}, context: {{context}})
end

# Wraps a constant value under a module into mruby.
Expand Down Expand Up @@ -339,13 +339,13 @@ module MrbWrap

{% new_context = crystal_class %}

{% if resolved_class.annotation(MrbWrap::RenameClass) %}
{% actual_name = resolved_class.annotation(MrbWrap::RenameClass)[0] %}
{% if resolved_class.annotation(Anyolite::RenameClass) %}
{% actual_name = resolved_class.annotation(Anyolite::RenameClass)[0] %}
{% else %}
{% actual_name = crystal_class.names.last.stringify %}
{% end %}

MrbWrap.wrap_class({{mrb_state}}, {{resolved_class}}, {{actual_name}}, under: {{under}})
Anyolite.wrap_class({{mrb_state}}, {{resolved_class}}, {{actual_name}}, under: {{under}})

MrbMacro.wrap_all_instance_methods({{mrb_state}}, {{crystal_class}}, {{instance_method_exclusions}},
{{verbose}}, context: {{new_context}}, use_enum_constructor: {{use_enum_constructor}})
Expand Down Expand Up @@ -374,13 +374,13 @@ module MrbWrap

{% new_context = crystal_module %}

{% if crystal_module.resolve.annotation(MrbWrap::RenameModule) %}
{% actual_name = crystal_module.resolve.annotation(MrbWrap::RenameModule)[0] %}
{% if crystal_module.resolve.annotation(Anyolite::RenameModule) %}
{% actual_name = crystal_module.resolve.annotation(Anyolite::RenameModule)[0] %}
{% else %}
{% actual_name = crystal_module.names.last.stringify %}
{% end %}

MrbWrap.wrap_module({{mrb_state}}, {{crystal_module.resolve}}, {{actual_name}}, under: {{under}})
Anyolite.wrap_module({{mrb_state}}, {{crystal_module.resolve}}, {{actual_name}}, under: {{under}})

MrbMacro.wrap_all_class_methods({{mrb_state}}, {{crystal_module}}, {{class_method_exclusions}}, {{verbose}}, context: {{new_context}})
MrbMacro.wrap_all_constants({{mrb_state}}, {{crystal_module}}, {{constant_exclusions}}, {{verbose}}, context: {{new_context}})
Expand All @@ -405,13 +405,13 @@ module MrbWrap
{% if !crystal_module_or_class.is_a?(Path) %}
{% puts "\e[31m> WARNING: Object #{crystal_module_or_class} of #{crystal_module_or_class.class_name.id} is neither a class nor module, so it will be skipped\e[0m" %}
{% elsif crystal_module_or_class.resolve.module? %}
MrbWrap.wrap_module_with_methods({{mrb_state}}, {{crystal_module_or_class}}, under: {{under}},
Anyolite.wrap_module_with_methods({{mrb_state}}, {{crystal_module_or_class}}, under: {{under}},
class_method_exclusions: {{class_method_exclusions}},
constant_exclusions: {{constant_exclusions}},
verbose: {{verbose}}
)
{% elsif crystal_module_or_class.resolve.class? || crystal_module_or_class.resolve.struct? %}
MrbWrap.wrap_class_with_methods({{mrb_state}}, {{crystal_module_or_class}}, under: {{under}},
Anyolite.wrap_class_with_methods({{mrb_state}}, {{crystal_module_or_class}}, under: {{under}},
instance_method_exclusions: {{instance_method_exclusions}},
class_method_exclusions: {{class_method_exclusions}},
constant_exclusions: {{constant_exclusions}},
Expand All @@ -420,15 +420,15 @@ module MrbWrap
{% elsif crystal_module_or_class.resolve.union? %}
{% puts "\e[31m> WARNING: Wrapping of unions not supported, thus skipping #{crystal_module_or_class}\e[0m" %}
{% elsif crystal_module_or_class.resolve < Enum %}
MrbWrap.wrap_class_with_methods({{mrb_state}}, {{crystal_module_or_class}}, under: {{under}},
Anyolite.wrap_class_with_methods({{mrb_state}}, {{crystal_module_or_class}}, under: {{under}},
instance_method_exclusions: {{instance_method_exclusions}},
class_method_exclusions: {{class_method_exclusions}},
constant_exclusions: {{constant_exclusions}},
use_enum_constructor: true,
verbose: {{verbose}}
)
{% elsif crystal_module_or_class.resolve.is_a?(TypeNode) %}
MrbWrap.wrap_class_with_methods({{mrb_state}}, {{crystal_module_or_class}}, under: {{under}},
Anyolite.wrap_class_with_methods({{mrb_state}}, {{crystal_module_or_class}}, under: {{under}},
instance_method_exclusions: {{instance_method_exclusions}},
class_method_exclusions: {{class_method_exclusions}},
constant_exclusions: {{constant_exclusions}},
Expand Down
2 changes: 1 addition & 1 deletion src/MrbCast.cr
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module MrbCast
new_ruby_object = MrbInternal.new_empty_object(mrb, ruby_class, ptr.as(Void*), MrbTypeCache.register(typeof(value), destructor))

struct_wrapper = MrbMacro.convert_from_ruby_struct(mrb, new_ruby_object, typeof(value))
struct_wrapper.value = MrbWrap::StructWrapper(typeof(value)).new(value)
struct_wrapper.value = Anyolite::StructWrapper(typeof(value)).new(value)

MrbRefTable.add(MrbRefTable.get_object_id(struct_wrapper.value), ptr.as(Void*))

Expand Down
Loading

0 comments on commit af742e7

Please sign in to comment.