module

Myst::NativeLib

Instance methods

call_func(itr, func : TFunctor, args : Array(MTValue), receiver : MTValue | Nil = nil)

Mimic the functionality of a Call, but without the lookup of the function. The function can be either a native function or a source-level function. The results do not affect the stack, the result of calling the function will be returned directly.

Source
call_func_by_name(itr, receiver : MTValue, name : String, args : Array(MTValue))

Same as call_func, but the function to call is given as a name to look up on the given receiver.

Source
instantiate(itr, type : TType, params : Array(MTValue)) : TInstance

Instantiate a given type and invoke its initializer

Source

Macros

def_instance_method(type, name, impl_name)
Source
def_method(type, name, impl_name)
Source
method(name, this_type, *params, &block)
Source
passthrough(call, return_nil = false, may_raise = nil)

Generate the code needed to create a passthrough method for some native Crystal method. call is a Call node representing the structure of the method being wrapped. For example:

NativeLib.passthrough File.basename(path : String)

This will generate the code:

NativeLib.method :passthrough_File_basename, MTValue, path : String do File.basename(path) end

If a method is expected to return nil, set return_nil to true. This will ensure that the method explicitly returns Myst's TNil value.

If the native method may raise an error, set may_raise to the type of the expected errors. This will ensure that any raised error is captured and instead raised as a Myst runtime error (meaning users will be able to catch it at runtime). Errors that are not of the given type will not be captured and will be shown as Interpreter Errors to the user.

Note that using this method requires that the given Call provide type restrictions for every argument.

Source