module Anyolite

Overview

Main wrapper module, which should be covering most of the use cases.

Defined in:

Macro.cr
Main.cr
Preloader.cr
RbArgCache.cr
RbCast.cr
RbClass.cr
RbClassCache.cr
RbInterpreter.cr
RbModule.cr
RbRefTable.cr
RbTypeCache.cr
helper_classes/AnyolitePointer.cr
helper_classes/HelperClasses.cr
implementations/mruby/FormatString.cr
implementations/mruby/Implementation.cr
implementations/mruby/KeywordArgStruct.cr
implementations/mruby/RbCore.cr
macros/ArgConversions.cr
macros/ArgTuples.cr
macros/FunctionCalls.cr
macros/FunctionGenerators.cr
macros/ObjectAllocations.cr
macros/RubyConversions.cr
macros/RubyTypes.cr
macros/UnionCasts.cr
macros/WrapAll.cr
macros/WrapMethodIndex.cr
macros/Wrappers.cr

Constant Summary

Undef = Undefined.new

Undefined mruby value.

Class Method Summary

Macro Summary

Class Method Detail

def self.create_rb_ref(obj) #

Wraps any Crystal object into an RbRef, securing it from the Ruby GC. This prevents the object from being deleted in Ruby, as long as this reference exists in Crystal.

Note that this might lead to memory leaks if you close the Ruby interpreter before all of these objects are cleaned up properly using the Crystal GC. However, this is only a problem if you open much more than one interpreter while running a program.


[View source]
def self.disable_program_execution #

Disables any function that allows for running external programs


[View source]
def self.get_interpreter_depth #

Returns the depth of interpreter calls


[View source]

Macro Detail

macro call_rb_block(block_value, args = nil, cast_to = nil, context = nil) #

Calls the Ruby block block_value, given as a RbRef, with the arguments args as an Array of castable Crystal values (nil for none).

If cast_to is set to a Class or similar, it will automatically cast the result to a Crystal value of that class, otherwise, it will return a RbRef value containing the result.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro call_rb_class_method(name, args = nil, block = nil, cast_to = nil, context = nil) #

Calls the Ruby method with String or Symbol name for self.class and the arguments args as an Array of castable Crystal values (nil for none).

An additional block can be passed as RbRef block.

If cast_to is set to a Class or similar, it will automatically cast the result to a Crystal value of that class, otherwise, it will return a RbRef value containing the result.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro call_rb_method(name, args = nil, block = nil, cast_to = nil, context = nil) #

Calls the Ruby method with String or Symbol name for self and the arguments args as an Array of castable Crystal values (nil for none).

An additional block can be passed as RbRef block.

If cast_to is set to a Class or similar, it will automatically cast the result to a Crystal value of that class, otherwise, it will return a RbRef value containing the result.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro call_rb_method_of_class(crystal_class, name, args = nil, block = nil, cast_to = nil, context = nil) #

Calls the Ruby method with String or Symbol name for the Crystal Class, Module or String crystal_class and the arguments args as an Array of castable Crystal values (nil for none).

An additional block can be passed as RbRef block.

If cast_to is set to a Class or similar, it will automatically cast the result to a Crystal value of that class, otherwise, it will return a RbRef value containing the result.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro call_rb_method_of_object(value, name, args = nil, block = nil, cast_to = nil, context = nil) #

Calls the Ruby method with String or Symbol name for the Crystal object or RbRef value and the arguments args as an Array of castable Crystal values (nil for none).

An additional block can be passed as RbRef block.

If cast_to is set to a Class or similar, it will automatically cast the result to a Crystal value of that class, otherwise, it will return a RbRef value containing the result.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro cast_to_crystal(rbref, cast_type, context = nil) #

Casts the RbRef rbref to the Crystal Class cast_type.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro does_class_respond_to(crystal_class, name) #

Checks whether the Ruby function name (String or Symbol) is defined for the Crystal Class, Module or String crystal_class.


[View source]
macro does_obj_respond_to(value, name) #

Checks whether the Ruby function name (String or Symbol) is defined for the Crystal object or RbRef value.


[View source]
macro eval(str, cast_to = nil, context = nil) #

Calls the Ruby expression str.

If cast_to is set to a Class or similar, it will automatically cast the result to a Crystal value of that class, otherwise, it will return a RbRef value containing the result.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro get_cv(crystal_class, name, cast_to = nil, context = nil) #

Gets the Ruby class variable with String or Symbol name for the Crystal Class, Module or String crystal_class.

If cast_to is set to a Class or similar, it will automatically cast the result to a Crystal value of that class, otherwise, it will return a RbRef value containing the result.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro get_gv(name, cast_to = nil, context = nil) #

Gets the Ruby global variable with String or Symbol name.

If cast_to is set to a Class or similar, it will automatically cast the result to a Crystal value of that class, otherwise, it will return a RbRef value containing the result.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro get_iv(object, name, cast_to = nil, context = nil) #

Gets the Ruby instance variable with String or Symbol name for the Crystal object or RbRef object.

If cast_to is set to a Class or similar, it will automatically cast the result to a Crystal value of that class, otherwise, it will return a RbRef value containing the result.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro get_rb_class_obj_of(crystal_class) #

Returns the RbValue of the Class, Module or String crystal_class.


[View source]
macro implementation #

Returns the current implementation (either :mruby or :mri) as a Symbol.


[View source]
macro link_libraries #

[View source]
macro obtain_given_rb_block #

Returns a cached block argument (or nil, if none given) in form of a RbRef, if enabled. Otherwise, an error will be triggered.


[View source]
macro raise_argument_error(message) #

Raises a Ruby argument error with String message.


[View source]
macro raise_index_error(message) #

Raises a Ruby index error with String message.


[View source]
macro raise_key_error(message) #

Raises a Ruby key error with String message.


[View source]
macro raise_name_error(message) #

Raises a Ruby name error with String message.


[View source]
macro raise_not_implemented_error(message) #

Raises a Ruby non-implementation error with String message.


[View source]
macro raise_range_error(message) #

Raises a Ruby range error with String message.


[View source]
macro raise_runtime_error(message) #

Raises a Ruby runtime error with String message.


[View source]
macro raise_script_error(message) #

Raises a Ruby script error with String message.


[View source]
macro raise_type_error(message) #

Raises a Ruby type error with String message.


[View source]
macro referenced_in_ruby?(value) #

Checks whether value is referenced in the current reference table.


[View source]
macro self_in_rb #

Returns current object as a RbRef


[View source]
macro set_cv(crystal_class, name, value) #

Sets the Ruby class variable with String or Symbol name for the Crystal Class, Module or String crystal_class to the value value.

If cast_to is set to a Class or similar, it will automatically cast the result to a Crystal value of that class, otherwise, it will return a RbRef value containing the result.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro set_gv(name, value) #

Sets the Ruby global variable with String or Symbol name to the Crystal value value.

If cast_to is set to a Class or similar, it will automatically cast the result to a Crystal value of that class, otherwise, it will return a RbRef value containing the result.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro set_iv(object, name, value) #

Sets the Ruby instance variable with String or Symbol name for the Crystal object or RbRef object to the Crystal value value.

If cast_to is set to a Class or similar, it will automatically cast the result to a Crystal value of that class, otherwise, it will return a RbRef value containing the result.

If needed, context can be set to a Path in order to specify cast_to.


[View source]
macro wrap(rb_interpreter, crystal_module_or_class, under = nil, instance_method_exclusions = [] of String | Symbol, class_method_exclusions = [] of String | Symbol, constant_exclusions = [] of String | Symbol, connect_to_superclass = false, include_ancestor_methods = true, use_enum_methods = false, wrap_equality_method = false, overwrite = false, verbose = false) #

Wraps a whole class or module structure under a module into mruby.

The class or module crystal_module_or_class will be integrated into the RbInterpreter rb_interpreter, with the optional parent module under. Methods or constants to be excluded can be specified as Symbol or String in the Array class_method_exclusions (for class methods) or constant_exclusions (for constants).

If wrap_equality_method is set, the == method will be wrapped automatically. Setting connect_to_superclass to false will force the algorithm to ignore any superclass. Setting include_ancestor_methods will include any methods from nontrivial ancestor classes. The option overwrite will iterate through all functions and constants again if set to true. If verbose is set, wrapping information will be displayed.


[View source]
macro wrap_class(rb_interpreter, crystal_class, name, under = nil, superclass = nil) #

Wraps a Crystal class directly into an mruby class.

The Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter, with name as its new designation, returning an Anyolite::RbClass.

To inherit from another mruby class, specify an Anyolite::RbClass as a superclass.

Each class can be defined in a specifiy module by setting under to a Anyolite::RbModule.


[View source]
macro wrap_class_getter(rb_interpreter, crystal_class, name, proc, operator = "", context = nil) #

Wraps a class getter into mruby.

The class getter proc of the Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter.

Its new name will be name.

The value operator will append the specified String to the final name and context can give the function a Path for resolving types correctly.


[View source]
macro wrap_class_method(rb_interpreter, crystal_class, name, proc, proc_args = nil, operator = "", context = nil, return_nil = false, block_arg_number = nil, block_return_type = nil, store_block_arg = false) #

Wraps a class method into mruby.

The class method proc of the Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter, with the arguments proc_args as an Array of Class.

Its new name will be name.

The value operator will append the specified String to the final name and context can give the function a Path for resolving types correctly. The value return_nil will override any returned value with nil.

The arguments block_arg_number and block_return_type can be set to an Int and a Class, respectively, in order to require a block argument. If store_block_arg is set to true, any block argument given will be stored in a cache.


[View source]
macro wrap_class_method_with_keywords(rb_interpreter, crystal_class, name, proc, keyword_args, regular_args = nil, operator = "", context = nil, return_nil = false, block_arg_number = nil, block_return_type = nil, store_block_arg = false) #

Wraps a class method into mruby, using keyword arguments.

The class method proc of the Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter, with the arguments regular_args as an Array of Class and keyword_args as an Array of TypeDeclaration.

Its new name will be name.

The value operator will append the specified String to the final name and context can give the function a Path for resolving types correctly. The value return_nil will override any returned value with nil.

The arguments block_arg_number and block_return_type can be set to an Int and a Class, respectively, in order to require a block argument. If store_block_arg is set to true, any block argument given will be stored in a cache.


[View source]
macro wrap_class_property(rb_interpreter, crystal_class, name, proc, proc_arg, operator_getter = "", operator_setter = "=", context = nil) #

Wraps a class property into mruby.

The class property proc of the Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter, with the argument proc_arg as its respective Class.

Its new name will be name.

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.


[View source]
macro wrap_class_setter(rb_interpreter, crystal_class, name, proc, proc_arg, operator = "=", context = nil) #

Wraps a class setter into mruby.

The class setter proc (without the =) of the Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter, with the argument proc_arg as its respective Class.

Its new name will be name.

The value operator will append the specified String to the final name and context can give the function a Path for resolving types correctly.


[View source]
macro wrap_class_with_methods(rb_interpreter, crystal_class, under = nil, instance_method_exclusions = [] of String | Symbol, class_method_exclusions = [] of String | Symbol, constant_exclusions = [] of String | Symbol, use_enum_methods = false, wrap_equality_method = false, connect_to_superclass = true, include_ancestor_methods = true, overwrite = false, verbose = false) #

Wraps a whole class structure under a module into mruby.

The Class crystal_class will be integrated into the RbInterpreter rb_interpreter, with the optional parent module under. Methods or constants to be excluded can be specified as Symbol or String in the Array instance_method_exclusions (for instance methods), class_method_exclusions (for class methods) or constant_exclusions (for constants).

Enum classes can be wrapped by setting use_enum_methods. If wrap_equality_method is set, the == method will be wrapped automatically. Setting connect_to_superclass to false will force the algorithm to ignore any superclass. Setting include_ancestor_methods will include any methods from nontrivial ancestor classes. The option overwrite will iterate through all functions and constants again if set to true. If verbose is set, wrapping information will be displayed.


[View source]
macro wrap_constant(rb_interpreter, under_module, name, crystal_value) #

Wraps a constant value under a module into mruby.

The value crystal_value will be integrated into the RbInterpreter rb_interpreter, with the name name and the parent module under_module.


[View source]
macro wrap_constant_under_class(rb_interpreter, under_class, name, crystal_value) #

Wraps a constant value under a class into mruby.

The value crystal_value will be integrated into the RbInterpreter rb_interpreter, with the name name and the parent Class under_class.


[View source]
macro wrap_constructor(rb_interpreter, crystal_class, proc_args = nil, operator = "", context = nil, block_arg_number = nil, block_return_type = nil, store_block_arg = false) #

Wraps the constructor of a Crystal class into mruby.

The constructor for the Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter, with the arguments proc_args as an Array of Class.

The value operator will append the specified String to the final name and context can give the function a Path for resolving types correctly.

The arguments block_arg_number and block_return_type can be set to an Int and a Class, respectively, in order to require a block argument. If store_block_arg is set to true, any block argument given will be stored in a cache.


[View source]
macro wrap_constructor_with_keywords(rb_interpreter, crystal_class, keyword_args, regular_args = nil, operator = "", context = nil, block_arg_number = nil, block_return_type = nil, store_block_arg = false) #

Wraps the constructor of a Crystal class into mruby, using keyword arguments.

The constructor for the Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter, with the arguments regular_args as an Array of Class and keyword_args as an Array of TypeDeclaration.

The value operator will append the specified String to the final name and context can give the function a Path for resolving types correctly.

The arguments block_arg_number and block_return_type can be set to an Int and a Class, respectively, in order to require a block argument. If store_block_arg is set to true, any block argument given will be stored in a cache.


[View source]
macro wrap_getter(rb_interpreter, crystal_class, name, proc, operator = "", context = nil) #

Wraps a getter into mruby.

The getter proc of the Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter.

Its new name will be name.

The value operator will append the specified String to the final name and context can give the function a Path for resolving types correctly.


[View source]
macro wrap_instance_method(rb_interpreter, crystal_class, name, proc, proc_args = nil, operator = "", context = nil, return_nil = false, block_arg_number = nil, block_return_type = nil, store_block_arg = false) #

Wraps an instance method into mruby.

The instance method proc of the Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter, with the arguments proc_args as an Array of Class.

Its new name will be name.

The value operator will append the specified String to the final name and context can give the function a Path for resolving types correctly. The value return_nil will override any returned value with nil.

The arguments block_arg_number and block_return_type can be set to an Int and a Class, respectively, in order to require a block argument. If store_block_arg is set to true, any block argument given will be stored in a cache.


[View source]
macro wrap_instance_method_with_keywords(rb_interpreter, crystal_class, name, proc, keyword_args, regular_args = nil, operator = "", context = nil, return_nil = false, block_arg_number = nil, block_return_type = nil, store_block_arg = false) #

Wraps an instance method into mruby, using keyword arguments.

The instance method proc of the Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter, with the arguments regular_args as an Array of Class and keyword_args as an Array of TypeDeclaration.

Its new name will be name.

The value operator will append the specified String to the final name and context can give the function a Path for resolving types correctly. The value return_nil will override any returned value with nil.

The arguments block_arg_number and block_return_type can be set to an Int and a Class, respectively, in order to require a block argument. If store_block_arg is set to true, any block argument given will be stored in a cache.


[View source]
macro wrap_module(rb_interpreter, crystal_module, name, under = nil) #

Wraps a Crystal module into an mruby module.

The module crystal_module will be integrated into the RbInterpreter rb_interpreter, with name as its new designation, returning an Anyolite::RbModule.

The parent module can be specified with the module argument under.


[View source]
macro wrap_module_function(rb_interpreter, under_module, name, proc, proc_args = nil, operator = "", context = nil, return_nil = false, block_arg_number = nil, block_return_type = nil, store_block_arg = false) #

Wraps a module function into mruby.

The function proc under the module under_module will be integrated into the RbInterpreter rb_interpreter, with the arguments proc_args as an Array of Class.

Its new name will be name.

The value operator will append the specified String to the final name and context can give the function a Path for resolving types correctly. The value return_nil will override any returned value with nil.

The arguments block_arg_number and block_return_type can be set to an Int and a Class, respectively, in order to require a block argument. If store_block_arg is set to true, any block argument given will be stored in a cache.


[View source]
macro wrap_module_function_with_keywords(rb_interpreter, under_module, name, proc, keyword_args, regular_args = nil, operator = "", context = nil, return_nil = false, block_arg_number = nil, block_return_type = nil, store_block_arg = false) #

Wraps a module function into mruby, using keyword arguments.

The function proc under the module under_module will be integrated into the RbInterpreter rb_interpreter, with the arguments regular_args as an Array of Class and keyword_args as an Array of TypeDeclaration.

Its new name will be name.

The value operator will append the specified String to the final name and context can give the function a Path for resolving types correctly. The value return_nil will override any returned value with nil.

The arguments block_arg_number and block_return_type can be set to an Int and a Class, respectively, in order to require a block argument. If store_block_arg is set to true, any block argument given will be stored in a cache.


[View source]
macro wrap_module_with_methods(rb_interpreter, crystal_module, under = nil, class_method_exclusions = [] of String | Symbol, constant_exclusions = [] of String | Symbol, overwrite = false, verbose = false) #

Wraps a whole module structure under a module into mruby.

The module crystal_module will be integrated into the RbInterpreter rb_interpreter, with the optional parent module under. Methods or constants to be excluded can be specified as Symbol or String in the Array class_method_exclusions (for class methods) or constant_exclusions (for constants). The option overwrite will iterate through all functions and constants again if set to true. If verbose is set, wrapping information will be displayed.


[View source]
macro wrap_property(rb_interpreter, crystal_class, name, proc, proc_arg, operator_getter = "", operator_setter = "=", context = nil) #

Wraps a property into mruby.

The property proc of the Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter, with the argument proc_arg as its respective Class.

Its new name will be name.

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.


[View source]
macro wrap_setter(rb_interpreter, crystal_class, name, proc, proc_arg, operator = "=", context = nil) #

Wraps a setter into mruby.

The setter proc (without the =) of the Crystal Class crystal_class will be integrated into the RbInterpreter rb_interpreter, with the argument proc_arg as its respective Class.

Its new name will be name.

The value operator will append the specified String to the final name and context can give the function a Path for resolving types correctly.


[View source]