GithubHelp home page GithubHelp logo

zhangpingfan / flutter_quickjs Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 0.0 3.05 MB

Flutter bindings for QuickJS with dart:ffi.

Home Page: https://pub.dev/packages/flutter_quickjs

License: MIT License

CMake 0.03% Kotlin 0.05% C++ 0.30% C 90.27% Makefile 0.78% JavaScript 7.24% Shell 0.21% Ruby 0.08% Swift 0.03% Objective-C 0.02% Dart 0.99%
quickjs flutter-bindings ffi dart flutter ios android javascript js

flutter_quickjs's Introduction

flutter_quickjs

Flutter bindings with dart:ffi for QuickJS : A small Javascript engine supports ES2020.

This is a plugin help execute javascript on flutter app, which is convenient to use with simple apis, and it supports iOS, Android now.

Install

To use this plugin, add flutter_quickjs as a dependency in your pubspec.yaml file.

CocoaPods: >= 1.10.0

Usage

Basic Example

import 'package:flutter/material.dart';
import 'package:flutter_quickjs/flutter_quickjs.dart';

void main() {
  var evalResult = runJs();
  runApp(
    MaterialApp(
      home: Material(
        child: Center(
          child: Text(evalResult),
        ),
      ),
    ),
  );
}

runJs() {
  var qjs = FlutterQuickjs();
  var res = qjs.eval('Math.PI');
  qjs.close();
  return res.toString();
}

Global Object

qjs.eval('var a = 666;');
print(qjs.global()['a']);
// 666

Set Value

qjs.setValue('globalThis.console.log', (msg) {
  print(msg);
});
qjs.eval('console.log("hello world!")');
// hello world!

JS Function Call

var func = qjs.eval('function func(a, b){return [a, b, a + b];}func');
print(func(2,3));
// [2, 3, 5]

For more usages please see example

Datatype Mapping

dart js
null Undefined / Null
Bool Boolean
Int Number
Double Number
String String
List Array
Map Object
Function Function
Exception Error

Todo

  • bytecode support
  • support more platforms like macos,linux

Reference

Lincense

MIT © ZhangPingFan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.