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

Appearance settings

PlutoLang/PlutoScript

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PlutoScript

Provides <script type="pluto"> and high-level APIs.

Usage

You simply need to load a suitable WASM build of libpluto, and then PlutoScript itself:

<script src="https://pluto-lang.org/wasm-builds/out/libpluto/0.12.0/libpluto.js"></script>
<script src="https://pluto-lang.org/PlutoScript/plutoscript.js"></script>

Example

A simple example is the Base32 Encoder tool that is available online here.

Barring the script tags needed for PlutoScript's usage, this is the entire source code:

<textarea id="plain"></textarea>
<textarea id="encoded"></textarea>
<script type="pluto">
    document.getElementById("plain"):addEventListener("input", function()
        document.getElementById("encoded").value = require"base32".encode(document.getElementById("plain").value)
    end)
</script>

JavaScript API

  • pluto_require(src)
  • pluto_load(code)
  • pluto_invoke(name, ...args) can be used to invoke a global Pluto function
  • pluto_give_file(name, data) writes a string or Uint8Array for Pluto code to read from the file with the given name

Pluto API

  • js_invoke(name, ...args) can be used to invoke a global JavaScript function
  • window.__index.__call: You can call any method on 'window', e.g. window.alert("Hello")
  • document.getElementById(x) returns an Element instance with path $"#{x}"
  • document.querySelector(x) returns an Element instance with path x
  • Element.__index/Element.__newindex: You can read and write any property of an Element, e.g. .value
  • Element:addEventListener(evt, func)
  • Element:addClass(name)
  • Element:removeClass(name)
  • Element:setAttribute(name, value)
  • Element:removeAttribute(name)

About

Provides <script type="pluto"> and high-level APIs.

Topics

Resources

License

Stars

Watchers

Forks

Morty Proxy This is a proxified and sanitized view of the page, visit original site.