Enum kailua_types::ty::Tag
[−]
[src]
pub enum Tag { Require, Type, Assert, AssertNot, AssertType, GenericPairs, GlobalEnv, GlobalEval, BecomeModule, PackagePath, PackageCpath, StringMeta, MakeClass(ClassSystemId), KailuaGenTvar, KailuaAssertTvar, // some variants omitted }
A type tag for giving a type special meanings.
Generally a type with a tag is equal to or a subtype of a specific form of types; it is safe to put a tag to an non-conforming type, but that won't work well in general.
Variants
Require
function(string, ...) -> table
Also loads a code specified by the string literal (if any). Any exported types in that cdoe will be also brought to the current local scope.
Type
function(any) -> string
Used by assertions but does nothing by its own. Has very limited return values.
Assert
function(any, ...) -> any
Also recognizes the following kinds of expressions:
<expr>
asserts that the corresponding type is truthy.not <expr>
asserts that the corresponding type is falsy.<type>(<expr>) == <string>
, where<type>
is a value withType
tag.
Expressions can be chained by and
or or
, subject to De Morgan's law.
Any unrecognized expression or non-definitive conditions are ignored.
AssertNot
function(any, ...) -> any
Same to assert(not <expr>, ...)
.
AssertType
function(any, string, ...) -> any
Basically same to assert(type(<expr>) == <string>, ...)
.
Also accepts additional string literals:
"integer"
for an integer.
GenericPairs
function(table, ...) -> (function(table, any) -> (any?, any), table, any, ...)
A hack for supporting generic pairs
and ipairs
functions.
The first argument is exactly resolved first and the return values are updated
to fit the following generic signature if possible (not yet directly supported):
({T => U}, ...) -> (function({T => U}, T) -> (T?, U), {T => U}, T, ...)
...except when the third return type is not any, in which case T is replaced with
that parameter so that ipairs
(which T should be integer) works for any table types.
GlobalEnv
table
A table mirroring the global environment.
GlobalEval
function(...) -> (...)
Calling this function will alter the global environment in unspecified way, so it is no longer assumed to be known after the call.
BecomeModule
function(string, ...) -> (...)
Calling this function will enable the "module" mode in Lua 5.1.
PackagePath
var string
Assigning to these variables will update the require
paths (in the order).
They are distinct to each other, but otherwise have the same syntax to Lua's.
PackageCpath
StringMeta
table
The metatable for all strings. The method calls for string go through this table, and any modification to this table is immediately available to subsequent code.
Note that this table is linked to the current environment only by --# assume
;
there is no other valid way to get a table with such a type.
MakeClass(ClassSystemId)
function(<class prototype type>?) -> <class prototype type>
A function that makes a class prototype. If the argument is given, it should be another existing prototype that acts as a parent of a newly created prototype.
The prototype is initially unnamed; the first assignment to a local or global variable will set its name, and the name cannot be changed thereafter.
There may be additional behaviors depending on the class system used.
KailuaGenTvar
function() -> any
Issues a fresh type variable for each use. The return type is ignored. This is strictly for testing.
KailuaAssertTvar
function(any)
Fails when given type is not a type variable (no matter it is bounded or not). This is used for tests requiring a type variable to be resolved; By using this function we can ensure that we are indeed testing against a type variable.
Methods
impl Tag
[src]
fn from(attr: &Attr, resolv: &mut TypeResolver) -> Result<Option<Tag>>
fn name(&self) -> &'static str
fn scope_local(&self) -> bool
Returns true if the effect of this tag is local to the current scope.
Non-scope-local tags have a limited ability inside non-global scopes.
fn needs_subtype(&self) -> bool
Returns true if this tag needs the strict subtyping rule.
For example, it is NOT possible to update [type] function(any) -> string
with
a plain function(any) -> string
, it has to be [type] function(any) -> string
.
Generally the tag working via assignment should have this false.
Trait Implementations
impl Copy for Tag
[src]
impl Clone for Tag
[src]
fn clone(&self) -> Tag
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl PartialEq for Tag
[src]
fn eq(&self, __arg_0: &Tag) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Tag) -> bool
This method tests for !=
.