Index

Ufy Libraries

Introduction

Ufy comes with a few standard libraries (modules), either implemented in source or in machine code. This document deals with a standard ufy configuration. Since it's possible that the interpreter that you're running has been set up differently, not all of this may apply to your situation. The situation that'll be described here is the one where each script loads the '$lang' module, and where 'std' is an alias for the 'stdio', 'string', 'stdlib', 'time', 'net' and 'types' modules, which are all described here.

About modules

All modules share a single namespace, which consists of identifiers, optionally separated by slashes. A dollar-sign at the beginning indicates a standard, native library, since it's illegal to declare a module-name with such a character through the '#module' directive, but it's legal to resolve a module-name with such a dollar-sign. Functions and classes are not sorted alphabetically; they are grouped more or less by type.

Module '$lang'

Functions and classes

Function 'byte'

Back to Top | Back to '$lang'

Function 'int'

Back to Top | Back to '$lang'

Function 'float'

Back to Top | Back to '$lang'

Function 'string'

Back to Top | Back to '$lang'

Function 'list'

Back to Top | Back to '$lang'

Function 'callable'

Back to Top | Back to '$lang'

Function 'isvoid'

Back to Top | Back to '$lang'

Function 'isbyte'

Back to Top | Back to '$lang'

Function 'isint'

Back to Top | Back to '$lang'

Function 'isfloat'

Back to Top | Back to '$lang'

Function 'isstring'

Back to Top | Back to '$lang'

Function 'islist'

Back to Top | Back to '$lang'

Function 'isobject'

Back to Top | Back to '$lang'

Function 'isfunction'

Back to Top | Back to '$lang'

Function 'exit'

Back to Top | Back to '$lang'

Function 'throw'

Usage:

throw(any);

Creates an error situation, which breaks down the stack of this thread, either until the end (also of the program execution), or until a fail, or a the end of an eval. The instance thrown can be caught using the catch function.

Back to Top | Back to '$lang' | Keyword fail | Function eval | Function catch

Function 'catch'

Usage:

var err = catch();

Or, more comprehensively:

try {
  1/0;
} fail {
  var err = catch();
  printf("Error: " + err);
}

Catches the error thrown, or the error object as generated by the interpreter upon encountering an erronous situation (as above; a division by zero).

Back to Top | Back to '$lang'

Function 'eval'

Usage:

var outcome = eval(code);

Evaluates a piece of code, captured inside a string.

Back to Top | Back to '$lang'

Function 'include'

Back to Top | Back to '$lang'

Function 'use'

Back to Top | Back to '$lang'

Function 'serialize'

Back to Top | Back to '$lang'

Function 'unserialize'

Back to Top | Back to '$lang'

Function 'call'

Usage:

var result = call(string, list);
var result = call(functor, list);
var result = call(object, string, list);
Wraps around a function call, in case the argument list can only be had as a proper list, or the name of the function can only be had as a string. Allows for variable argument lists to be passed on to the next function:
function foo_format(string fmt) {
  return "foo" + call("format", fmt, _);
}

Back to Top | Back to '$lang'

Function 'sizeof'

Back to Top | Back to '$lang'

Function 'delete'

Back to Top | Back to '$lang'

Function 'keys'

Back to Top | Back to '$lang'

Function 'values'

Back to Top | Back to '$lang'

Function 'put'

Back to Top | Back to '$lang'

Function 'pop'

Back to Top | Back to '$lang'

Function 'pop2'

Back to Top | Back to '$lang'

Function 'wait'

Usage:

wait(object);
wait();
Blocks execution of the current thread, until the object is released. Calling wait() without arguments is only valid within the context of a class definition, as the object itself will be used to block.

Back to Top | Back to '$lang'

Function 'release'

Usage:

release(object);
release();
Releases one waiter on an object. Calling release() without arguments is only valid within the context of a class definition, as the object itself will be used.

Back to Top | Back to '$lang'

Function 'releaseAll'

Usage:

releaseAll(object);
releaseAll();
Releases all waiters on an object. Calling releaseAll() without arguments is only valid within the context of a class definition, as the object itself will be used.

Back to Top | Back to '$lang'

Function 'yield'

Usage:

yield(any);

Pushes an instance into the thread's FIFO to its parent thread, where it can be retrieved with the 'fetch' method.

Back to Top | Back to '$lang'

Class 'Thread'

Usage:

var thread = clone some_func();
thread.fetch();
thread.cancel();
thread.join();

The 'Thread' class is returned automatically from the clone keyword. It can be used to manipulate the execution of the child-thread, and to communicate with it. Threads have their own FIFO to communicate with their parent:

#use std

function slowyield() {
  for (i=0; i<4; i++) {
    printf("Thread yielding %a\n", i);
    yield(i);
    sleep(1);
  }
  printf("Thread exiting.\n");
}

var n, th = clone slowyield();
while (!isvoid(n = th.fetch())) {
  printf("Mainthread fetches %a\n", n);
}
printf("Mainthread exiting.\n");

Will result (slowly), in:

Thread yielding 0
Mainthread fetches 0
Thread yielding 1
Mainthread fetches 1
Thread yielding 2
Mainthread fetches 2
Thread yielding 3
Mainthread fetches 3
Thread exiting.
Mainthread exiting.

Back to Top | Back to '$lang'

Class 'Regex'

Back to Top | Back to '$lang'

Class 'object'

Back to Top | Back to '$lang'

Class 'Error'

Usage:

var error = Error();
var error = Error(string);
var error = Error(int, string);
error.add_string(string);
error.set_code(string);

Spoons up the current error state for your thread, optionally adding to it the parameters that you provide (the strings go first on the stack of error messages, the integer becomes the error code). The methods 'add_string' and 'set_code' perform those functions as well, but allow you to 're-throw' errors; the state of an original error is appended to, as is shown in the following example:

try {
  1/0;
} fail {
  var e = catch();
  e.add_string("You divided by zero !");
  throw(e);
}

Back to Top | Back to '$lang'

Function 'BREAKPOINT'

Usage:

BREAKPOINT();

Works only when the interpreter has been compiled with _DEBUG defined. Allows you to step throw your, and the interpreter's code.

Back to Top | Back to '$lang'

net / $net

Function 'clientsocket'

Back to Top | Back to 'net'

Function 'serversocket'

Back to Top | Back to 'net'

Function 'accept'

Back to Top | Back to 'net'

Function 'parse_url'

Back to Top | Back to 'net'

Function 'http_get'

Back to Top | Back to 'net'

stdio / $stdio

Function 'fopen'

Back to Top | Back to 'stdio'

Function 'fseek'

Back to Top | Back to 'stdio'

Function 'flock'

Back to Top | Back to 'stdio'

Function 'truncate'

Back to Top | Back to 'stdio'

Function 'rename'

Back to Top | Back to 'stdio'

Function 'remove'

Back to Top | Back to 'stdio'

Function 'mkdir'

Back to Top | Back to 'stdio'

Function 'chdir'

Back to Top | Back to 'stdio'

Function 'pwd'

Back to Top | Back to 'stdio'

Function 'exist'

Back to Top | Back to 'stdio'

Function 'stat'

Back to Top | Back to 'stdio'

Function 'dir'

Back to Top | Back to 'stdio'

Function 'tmpfile'

Back to Top | Back to 'stdio'

Function 'tmpname'

Back to Top | Back to 'stdio'

Function 'pipe'

Back to Top | Back to 'stdio'

Function 'realpath'

Back to Top | Back to 'stdio'

Function 'printf'

Back to Top | Back to 'stdio'

Function 'copy'

Back to Top | Back to 'stdio'

stdlib / $stdlib

Function 'rand'

Back to Top | Back to 'stdlib'

Function 'srand'

Back to Top | Back to 'stdlib'

Function 'getenv'

Back to Top | Back to 'stdlib'

Function 'setenv'

Back to Top | Back to 'stdlib'

Function 'system'

Back to Top | Back to 'stdlib'

string / $string

Function 'strlen'

Back to Top | Back to 'string'

Function 'toupper'

Back to Top | Back to 'string'

Function 'tolower'

Back to Top | Back to 'string'

Function 'charat'

Back to Top | Back to 'string'

Function 'substr'

Back to Top | Back to 'string'

Function 'strspn'

Back to Top | Back to 'string'

Function 'strcspn'

Back to Top | Back to 'string'

Function 'left'

Back to Top | Back to 'string'

Function 'right'

Back to Top | Back to 'string'

Function 'trim'

Back to Top | Back to 'string'

Function 'ltrim'

Back to Top | Back to 'string'

Function 'rtrim'

Back to Top | Back to 'string'

Function 'split'

Back to Top | Back to 'string'

Function 'join'

Back to Top | Back to 'string'

Function 'chop'

Back to Top | Back to 'string'

Function 'strstr'

Back to Top | Back to 'string'

Function 'format'

Back to Top | Back to 'string'

Function 'levenshtein'

Back to Top | Back to 'string'

Function 'b64encode'

Back to Top | Back to 'string'

Function 'b64decode'

Back to Top | Back to 'string'

Function 'htoni'

Back to Top | Back to 'string'

Function 'blob'

Back to Top | Back to 'string'

Function 'unblob'

Back to Top | Back to 'string'

Function 'sort'

Back to Top | Back to 'string'

Function 'hex'

Back to Top | Back to 'string'

time / $time

  • TM
  • time
  • utime
  • sleep
  • usleep
  • strftime

    Function 'TM'

    Back to Top | Back to 'time'

    Function 'time'

    Back to Top | Back to 'time'

    Function 'utime'

    Back to Top | Back to 'time'

    Function 'sleep'

    Back to Top | Back to 'time'

    Function 'usleep'

    Back to Top | Back to 'time'

    Function 'strftime'

    Back to Top | Back to 'time'


    Author: Kees Jan Hermans
    Date: 2006-07-06