This is the runtime and JavaScript engine that runs on Tessel, built on Lua's VM. It can be run independently on PC or embedded.
git clone update --init --recursive https://github.com/tessel/runtime.git
Building the firmware requires gcc-arm-embedded, gyp, and ninja.
To install quickly on a Mac with Brew:
brew tap tessel/tools
brew install gcc-arm gyp ninja
All dependencies are in the Ubuntu 14.04 repositories:
sudo apt-get install git nodejs npm nodejs-legacy gcc-arm-none-eabi gyp ninja-build
npm install
npm install -g colony-compiler
make colony
npm link --local
npm test
You can now run code on your PC using colony
from your command line. For building firmware, please see the firmware building instructions.
Colony has support for interacting with the Lua API for handling basic JavaScript primitives. These are included via colony.h
.
# void colony_createarray ( lua_State* L, int size )
Creates a new JavaScript array of length size
. This sets the object prototype as well as the initial length of the array.
# void colony_createobj ( lua_State* L, int size, int proto )
Creates a new JavaScript object with an expected (but not required) allocation of size
keys. This sets the object prototype as well. If proto
is not zero (an invalid stack pointer), it points to an object on the stack to be used as the prototype for the newly created object.
Networking
# typedef tm_socket_t
socket type
# tm_socket_t tm_udp_open ()
open a udp socket
# int tm_udp_close ( int sock )
close a udp socket
# int tm_udp_listen ( int ulSocket, int port )
listen to udp
# int tm_udp_receive ( int ulSocket, uint8_t *buf, unsigned long buf_len, uint32_t *ip );
receive on udp
# int tm_udp_readable ( tm_socket_t sock )
is socket readable?
# int tm_udp_send ( int ulSocket, uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3, int port, uint8_t *buf, unsigned long buf_len )
send on socket
# tm_socket_t tm_tcp_open ()
open tcp
# int tm_tcp_close ()
close tcp
# int tm_tcp_connect ( tm_socket_t sock, uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3, uint16_t port )
connect on tcp
# int tm_tcp_write ( tm_socket_t sock, uint8_t *buf, size_t buflen )
write on tcp
# int tm_tcp_read ( tm_socket_t sock, uint8_t *buf, size_t buflen )
read on tcp
# int tm_tcp_readable ( tm_socket_t sock )
is socket readable?
# int tm_tcp_listen ( tm_socket_t sock, uint16_t port )
listen on port
# tm_socket_t tm_tcp_accept ( tm_socket_t sock, uint32_t *ip )
accept new incoming connection
# uint32_t tm_hostname_lookup ( const uint8_t *hostname )
lookup host
Regexes
# typedef struct {
size_t re_nsub;
long re_info;
int re_csize;
} regex_t;
Regex created by re_comp
. re_nsub
is the number of subcapture groups. re_info
is a bitmask of information about the regex. re_csize
is the length of a character in the regex.
# typedef struct {
long rm_so;
long rm_eo;
} regmatch_t;
A matched subgroup. rm_so
is the start offset in the string, rm_eo
is the ending offset.
# int re_comp( regex_t* regex, const wchar_t* pattern, size_t pattern_len, int flags );
Compiles a regex pattern
with flags
in the memory allocated at regex
. Use regfree
to close this object.
# void regfree( regex_t* regex );
Frees the internals of a regex_t
object.
# int re_exec( regex_t* regex, const wchar_t* input, size_t input_len, rm_detail_t* details, size_t matches_len, regmatch_t matches[], int flags );
Executes a regex
on the given string input
. Can match up to matches_len
subgroups in the array matches
.
# size_t regerror( int error, const regex_t* regex, char* buf, size_t buf_len );
Returns the meaning of a given regex error.
MIT or Apache 2.0, at your option.