Software for the imp

Software that runs on the imp is written in Squirrel: a high level object oriented programming language with a syntax similar to C or JavaScript. More background is in Wikipedia's article on Squirrel.

The official Squirrel language documentation can be found at squirrel-lang.org (the imp uses a slightly modified version of Squirrel 3.0.4): Squirrel Reference Manual

All Squirrel programs on the imp will need to use at least some of the Electric Imp API, the objects and classes that encapsulate the imp hardware and its internet connection. Some may also need parts of the Squirrel standard libraries, also documented at squirrel-lang.org: Squirrel Standard Libraries Manual

Several example Squirrel programs, from the simplest-possible to the somewhat advanced, are provided on this wiki.

Differences from standard Squirrel

There are a few differences between the standard Squirrel libraries and imp Squirrel's libraries. The biggest one is that the Squirrel math library is in its own namespace, math. So where the official Squirrel documentation talks about, say, acos(), on an imp that would be math.acos(). Other differences are more minor and relate to operations that can't work on an imp: all the file handling calls, for instance, have been removed, as there's no filesystem on an imp.

Present on the imp Absent from the imp
Base library getroottable assert print error array type callee dummy setroottable getconsttable setconsttable compilestring newthread suspend setdebughook seterrorhandler getstackinfos
IO library all (except for stream methods on blobs)
Blob library all
Maths library all, but in namespace math, see above
System library clock time date getenv system remove rename
String library all except regexp class regexp class (but will be added in a future release)

Extensions to standard Squirrel

In a few places Squirrel has been extended in ways intended to benefit users of imps and/or agents:

  • instances of blob can be implicitly coerced to type string – or explicitly converted: blob.tostring()
  • indexing a string always produces character values in the range 0-255
    • standard Squirrel exposed the underlying C char type, so was signed on some platforms
  • the if (“X” in Y) construct now works even if Y has a delegate, or a metamethod get
    • this is what enables if (“pinA” in hardware)
learningsquirrel.txt · Last modified: 2013/04/11 15:55 by peter
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki