module Anyolite
Overview
Main wrapper module, which should be covering most of the use cases.
Defined in:
Macro.crMain.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
-
.create_rb_ref(obj)
Wraps any Crystal object into an
RbRef
, securing it from the Ruby GC. -
.disable_program_execution
Disables any function that allows for running external programs
-
.get_interpreter_depth
Returns the depth of interpreter calls
Macro Summary
-
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 anArray
of castable Crystal values (nil
for none). -
call_rb_class_method(name, args = nil, block = nil, cast_to = nil, context = nil)
Calls the Ruby method with
String
orSymbol
name forself.class
and the arguments args as anArray
of castable Crystal values (nil
for none). -
call_rb_method(name, args = nil, block = nil, cast_to = nil, context = nil)
Calls the Ruby method with
String
orSymbol
name forself
and the arguments args as anArray
of castable Crystal values (nil
for none). -
call_rb_method_of_class(crystal_class, name, args = nil, block = nil, cast_to = nil, context = nil)
Calls the Ruby method with
String
orSymbol
name for the CrystalClass
,Module
orString
crystal_class and the arguments args as anArray
of castable Crystal values (nil
for none). -
call_rb_method_of_object(value, name, args = nil, block = nil, cast_to = nil, context = nil)
Calls the Ruby method with
String
orSymbol
name for the Crystal object orRbRef
value and the arguments args as anArray
of castable Crystal values (nil
for none). -
cast_to_crystal(rbref, cast_type, context = nil)
Casts the
RbRef
rbref to the CrystalClass
cast_type. -
does_class_respond_to(crystal_class, name)
Checks whether the Ruby function name (
String
orSymbol
) is defined for the CrystalClass
,Module
orString
crystal_class. -
does_obj_respond_to(value, name)
Checks whether the Ruby function name (
String
orSymbol
) is defined for the Crystal object orRbRef
value. -
eval(str, cast_to = nil, context = nil)
Calls the Ruby expression str.
-
get_cv(crystal_class, name, cast_to = nil, context = nil)
Gets the Ruby class variable with
String
orSymbol
name for the CrystalClass
,Module
orString
crystal_class. -
get_gv(name, cast_to = nil, context = nil)
Gets the Ruby global variable with
String
orSymbol
name. -
get_iv(object, name, cast_to = nil, context = nil)
Gets the Ruby instance variable with
String
orSymbol
name for the Crystal object orRbRef
object. -
get_rb_class_obj_of(crystal_class)
Returns the
RbValue
of theClass
,Module
orString
crystal_class. -
implementation
Returns the current implementation (either
:mruby
or:mri
) as aSymbol
. - link_libraries
-
obtain_given_rb_block
Returns a cached block argument (or
nil
, if none given) in form of aRbRef
, if enabled. -
raise_argument_error(message)
Raises a Ruby argument error with
String
message. -
raise_index_error(message)
Raises a Ruby index error with
String
message. -
raise_key_error(message)
Raises a Ruby key error with
String
message. -
raise_name_error(message)
Raises a Ruby name error with
String
message. -
raise_not_implemented_error(message)
Raises a Ruby non-implementation error with
String
message. -
raise_range_error(message)
Raises a Ruby range error with
String
message. -
raise_runtime_error(message)
Raises a Ruby runtime error with
String
message. -
raise_script_error(message)
Raises a Ruby script error with
String
message. -
raise_type_error(message)
Raises a Ruby type error with
String
message. -
referenced_in_ruby?(value)
Checks whether value is referenced in the current reference table.
-
self_in_rb
Returns current object as a
RbRef
-
set_cv(crystal_class, name, value)
Sets the Ruby class variable with
String
orSymbol
name for the CrystalClass
,Module
orString
crystal_class to the value value. -
set_gv(name, value)
Sets the Ruby global variable with
String
orSymbol
name to the Crystal value value. -
set_iv(object, name, value)
Sets the Ruby instance variable with
String
orSymbol
name for the Crystal object orRbRef
object to the Crystal value value. -
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.
-
wrap_class(rb_interpreter, crystal_class, name, under = nil, superclass = nil)
Wraps a Crystal class directly into an mruby class.
-
wrap_class_getter(rb_interpreter, crystal_class, name, proc, operator = "", context = nil)
Wraps a class getter into mruby.
-
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.
-
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.
-
wrap_class_property(rb_interpreter, crystal_class, name, proc, proc_arg, operator_getter = "", operator_setter = "=", context = nil)
Wraps a class property into mruby.
-
wrap_class_setter(rb_interpreter, crystal_class, name, proc, proc_arg, operator = "=", context = nil)
Wraps a class setter into mruby.
-
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.
-
wrap_constant(rb_interpreter, under_module, name, crystal_value)
Wraps a constant value under a module into mruby.
-
wrap_constant_under_class(rb_interpreter, under_class, name, crystal_value)
Wraps a constant value under a class into mruby.
-
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.
-
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.
-
wrap_getter(rb_interpreter, crystal_class, name, proc, operator = "", context = nil)
Wraps a getter into mruby.
-
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.
-
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.
-
wrap_module(rb_interpreter, crystal_module, name, under = nil)
Wraps a Crystal module into an mruby module.
-
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.
-
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.
-
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.
-
wrap_property(rb_interpreter, crystal_class, name, proc, proc_arg, operator_getter = "", operator_setter = "=", context = nil)
Wraps a property into mruby.
-
wrap_setter(rb_interpreter, crystal_class, name, proc, proc_arg, operator = "=", context = nil)
Wraps a setter into mruby.
Class Method Detail
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.
Disables any function that allows for running external programs
Macro Detail
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.
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.
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.
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.
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.
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.
Checks whether the Ruby function name (String
or Symbol
) is defined
for the Crystal Class
, Module
or String
crystal_class.
Checks whether the Ruby function name (String
or Symbol
) is defined
for the Crystal object or RbRef
value.
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.
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.
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.
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.
Returns the RbValue
of the Class
, Module
or String
crystal_class.
Returns a cached block argument (or nil
, if none given) in form of a RbRef
, if enabled.
Otherwise, an error will be triggered.
Raises a Ruby non-implementation error with String
message.
Checks whether value is referenced in the current reference table.
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.
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.
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.
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.
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
.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.