Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

JavaScript scripting engine Arduino IDE Library for ESP8266

License

NotificationsYou must be signed in to change notification settings

sfranzyshen/ESP8266-Arduino-JavaScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript scripting engine Arduino IDE Library for ESP8266

License: GPL v2

ESP8266-Arduino-JavaScript is a Arduino IDE Library to implement a JavaScript engine for ESP8266 microcontroller.

Library Install

  • Download the latest github release zip fileESP8266-Arduino-JavaScript-0.0.12
  • In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library. At the top of the drop down list, select the option to "Add .ZIP Library''.
  • You will be prompted to select the library you would like to add. Navigate to the .zip file's location and open it.
  • Load the demo sketch using the Arduino IDE menu (File->Examples->ESP8266-Arduino-JavaScript->blink)
  • Build and Upload.

Features

  • Clean ISO C, ISO C++. Builds on old (VC98) and modern compilers, from 8-bit (e.g. Arduino mini) to 64-bit systems
  • No dependencies
  • Implements a restricted subset of ES6 with limitations
  • Preallocates all necessary memory and never callsmalloc,reallocat run time. Upon OOM, the VM is halted
  • Object pool, property pool, and string pool sizes are defined at compile time
  • The minimal configuration takes only a few hundred bytes of RAM
  • RAM usage: an object takes 6 bytes, each property: 16 bytes,a string: length + 6 bytes, any other type: 4 bytes
  • Strings are byte strings, not Unicode.For example,'ы'.length === 2,'ы'[0] === '\xd1','ы'[1] === '\x8b'
  • Limitations: max string length is 256 bytes, numbers hold32-bit float value, no standard JS library
  • mJS VM executes JS source directly, no AST/bytecode is generated
  • Simple FFI API to inject existing C functions into JS

Example - blink in JavaScript on Arduino IDE ESP8266 Platform

#include<mjs3.h>externvoidmyDelay(int x) {delay(x);}externvoidmyDigitalWrite(int x,int y) {digitalWrite(x, y);}voidsetup() {pinMode(16, OUTPUT);// Initialize the LED_BUILTIN pin as an outputstructmjs *vm =mjs_create();// Create JS instancemjs_ffi(vm,"delay", (cfn_t) myDelay,"vi");// Import delay()mjs_ffi(vm,"write", (cfn_t) myDigitalWrite,"vii");// Import write()mjs_eval(vm,"while (1) { write(16, 0); delay(500); write(16, 1); delay(500); }", -1);}voidloop() {//delay(1000);}
Sketch uses 271568 bytes (26%) of program storage space. Maximum is 1044464 bytes.Global variables use 27828 bytes (33%) of dynamic memory, leaving 54092 bytes for local variables. Maximum is 81920 bytes.

Supported standard operations and constructs

NameOperation
OperationsAll but!=,==. Use!==,=== instead
typeoftypeof(...)
deletedelete obj.k
whilewhile (...) {...}
Declarationslet a, b, c = 12.3, d = 'a';
Simple typeslet a = null, b = undefined, c = false, d = true;
Functionslet f = function(x, y) { return x + y; };
Objectslet obj = {a: 1, f: function(x) { return x * 2}}; obj.f();
Arrayslet arr = [1, 2, 'hi there']

Unsupported standard operations and constructs

NameOperation
Loops/switchfor (...) { ... },for (let k in obj) { ... },do { ... } while (...),switch (...) {...}
Equality==,!= (note: use strict equality===,!==)
varvar ... (note: uselet ...)
Closureslet f = function() { let x = 1; return function() { return x; } };
Const, etcconst ...,await ... ,void ... ,new ...,instanceof ...
Standard typesNoDate,ReGexp,Function,String,Number
PrototypesNo prototype based inheritance

Supported non-standard JS API

FunctionDescription
s[offset]Return byte value atoffset.s is either a string, or a number. A number is interprepted asuint8_t * pointer. Example:'abc'[0] returns 0x61. To read a byte at address0x100, use0x100[0];.

LICENSE

Dual license: GPLv2 or commercial. For commerciallicensing, please contactsupport@mongoose-os.com

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp