Giter Club home page Giter Club logo

crjsc's Introduction

crjsc

crjsc bridges Crystal and the JavaScriptCore library. JavaScriptCore is the javascript engine that powers WebKit, the underlying framework for the Safari web browser and many other applications.

You can call javascript functions and read values from Crystal, and you can write Crystal classes and have them executed in Javascript. The goal of this library is to allow the most seemless back-and-forth between Javascript and Crystal that is possible. Pull requests, issues, comments and suggestions are gladly welcome.

This library is not suitable in production, and should be considered alpha level software.

Todo

  • Support calling js functions atached to js objects from crystal.
  • Add propper docs to classes
  • Explain jsprop
  • Allow wildcard getProperty and setProperty calls
  • Pass javascript arrays as special JSArray objects
  • Allow single functions to be dropped into js without requiring manual class handling (let top level functions be turned into js objects)
  • handle type restrictions and automatic? type conversion
  • Use callbacks definitions to dispatch arguments instead of having them shoved into an array

Installation

Add this to your application's shard.yml:

dependencies:
  crjsc:
    github: bmmcginty/crjsc

Usage

All of the following should be performed from the root of this repository.

  • To build, run make.
  • To test, run make spec.
  • To run the example(s), run make examples.

See examples/file_interface.cr for an example that exposes file access to Javascript.

Development

The JavaScriptCore library will be downloaded to src/ext/webkit. It will also be symlinked to jscore for quicker access. Use jscore/API to look at the C interface to JavaScriptCore. Make changes in src/crjsc/lib.cr or the appropriate file.

Low-level Notes

  • All JSObjects are (interchangeable) JSValues.
  • Not all JSValues are JSObjects. Use value_is_object to check this.
  • To convert a crystal type to Javascript, insure that a to_js(ctx) method exists, that it accepts a Crjsc::Context, and that it outputs a Crjsc::LibJavaScriptCore::Valueref (or in some cases a Crjsc::LibJavaScriptCore::Objectref).
  • To convert a Javascript type to a native Crystal type, insure that a to_cr method exists and returns a crystal type.
  • If you are accessing a complex JS object from Crystal, use the obj[name] and obj[name]=value method to access and mutate properties/functions of that object.

Contributing

  1. Fork it ( https://github.com/bmmcginty/crjsc/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • bmmcginty Brandon McGinty-Carroll - creator, maintainer

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.