Skip to content

Olegas/runtime

 
 

Repository files navigation

tessel runtime

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 --recursive https://github.com/tessel/runtime.git

Building the firmware requires gcc-arm-embedded, gyp, and ninja.

OS X

To install quickly on a Mac with Brew:

brew tap tessel/tools
brew install gcc-arm gyp ninja

If you get an error that looks like this:

==> Checking out http://gyp.googlecode.com/svn/trunk/
==> python setup.py install

  http://peak.telecommunity.com/EasyInstall.html

Please make the appropriate changes for your system and try again.


READ THIS: https://github.com/Homebrew/homebrew/wiki/troubleshooting
If reporting this issue please do so at (not Homebrew/homebrew):
  https://github.com/tessel/homebrew-tools/issues

Then try running this:

brew uninstall gyp
brew install python gyp ninja

And if that doesn't work, you could try brew install -vd gyp to get more information.

Ubuntu 14.04

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

Building

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 (e.g. colony hello-world.js). For building firmware, please see the firmware building instructions.

Documentation

Colony

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.

Net

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

Regular Expressions

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.

License

MIT or Apache 2.0, at your option.

About

Tessel JS runtime

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published