abstract class Ven::Suite::Extension

Overview

The base class of all built-in (that is, written in Crystal) libraries. To get a feel of a real extension, see Library::Core (src/ven/library/core.cr)

Included Modules

Direct Known Subclasses

Defined in:

ven/suite/extension.cr

Constructors

Instance Method Summary

Macro Summary

Constructor Detail

def self.new(context : Context) #

[View source]

Instance Method Detail

abstract def load #

#load is called when this extension is 'included'. It is thus a reasonable place to define all top-level things, i.e., the entities this extension exports.


[View source]

Macro Detail

macro deftype(name, model) #

Defines a Ven type. name is a String, and model is the Model.class the type 'matches' on, in other words, the type to-be-defined represents.

  deftype("num", Num)

[View source]
macro defun(name) #

Registers (makes visible) a Ven builtin function. name, a String, is the name of an existing, reachable Crystal method (see fun!)

    fun! greet, name : Str do |m|
       puts "Hi, #{name.value}!"
    end

    def load
      defun("greet")
    end

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

Defines a Ven symbol. name is a String, and value is a Model.

  defvar("PI", Num.new(3.14))

[View source]
macro fun!(name, *takes, &block) #

Defines a Crystal method, name, which returns a Proc to-be-used by Ven as the implementation of a builtin function. This returned proc performs an arity check and a type check based on takes, a sequence of TypeDeclarations. block is the block that will be executed after these checks, and is the body of the builtin function. It must accept (but not necessarily use) one argument, Machine. For a usage example, see defun.


[View source]