abstract class Ven::Suite::Extension
- Ven::Suite::Extension
- Reference
- Object
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.crConstructors
Instance Method Summary
Macro Summary
-
deftype(name, model)
Defines a Ven type.
-
defun(name)
Registers (makes visible) a Ven builtin function.
-
defvar(name, value)
Defines a Ven symbol.
-
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.
Constructor Detail
Instance Method Detail
#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.
Macro Detail
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)
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
Defines a Ven symbol. name is a String, and value
is a Model
.
defvar("PI", Num.new(3.14))
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
.