/nodekit-darwin-lite

Thinner version of NodeKit for iOS and Mac, using only native JavaScriptCore and JSExport

Primary LanguageSwiftApache License 2.0Apache-2.0

This repository contains a JavaScriptCore-only version of NodeKit.

It follows the full NodeKit API (NKScripting currently implemented) using only JSExport on JavaScriptCore.

Installation

Use Carthage (nodekit-io/nodekit-darwin-lite) or CocoaPods (NKScriptingLite)

API

NKScriptContextFactory

let options = Dictionary<String, AnyObject>()

NKScriptContextFactory().createScriptContext(options, delegate: self.scriptContextDelegate)

NKScriptContextDelegate

func NKScriptEngineDidLoad(context: NKScriptContext) -> Void 

func NKScriptEngineReady(context: NKScriptContext) -> Void {

NKScriptContext

func loadPlugin(object: AnyObject, namespace: String, options: Dictionary<String, AnyObject>) -> Void

func evaluateJavaScript(javaScriptString: String, completionHandler: ((AnyObject?,NSError?) -> Void)?)

Native Plugins that are exposed to JavaScript

Example to create plugin

context.loadPlugin(storage(), namespace: "io.nodekit.scripting.storage", options: ["js": "lib-scripting.nkar/lib-scripting/native_module.js"])

Plugins should implement an @objc protocol that injerits from NKScriptExport; each method in this protocol is exposed automatically to JavaScript

See SamplePlugin.swift for an example