Skip to content
Anand Chitipothu edited this page Apr 9, 2021 · 3 revisions

Welcome to the livecode wiki!

Vision

The goal of livecode project is make it easier to run any program directly from the browser.

Possible use cases

Wrtiting tutorials Use livecode to execute the code snippets in the tutorial.

Create exercises Use livecode to execute user's code and run test cases against it.

create interactive applications in the browser Use livecode to start an application and use a bidirectional channel to communite to the browser to propagate user events like mouse movements and key presses.

Interactive and Non-interactive modes

As one can see from the use cases, there are two different modes of use. Interactive and non-interactive.

In the non-interactive mode, the code is executed and the exit status and the output is returned back as a response. All this happens in one single request.

In the interactive mode, code execution starts a session on the server and a channel is provided to read the stream outputs from that session.

The most common use case is the non-interactive one.

Engines

The livecide will be implemented to work on multiple backends. The planned engines are:

  • docker
  • heroku
  • AWS Lambda
  • Cloudflare Workers

How to use

LiveCode will have a client library to make it easier to add the live code capabilities to an existing webpage, with a couple of lines of javacript.

Options:

  • convert all pre elements into livecode
  • convert all textareas into livecode

Demos

It would be good to make the following demos.

  • hello world
  • run tests against some code
  • terminal in a browser
  • draw a circle at the location of mouse

Protocol

Simple execution:

POST /sessions

{
    "runtime": "python",
    "code": "print('hello, world!')"
}
---
200 OK

{
    "exit_status": 0,
    "output": "hello, world!\n"
}

More complex example:

POST /sessions
{
    "runtime": "python",
    "code": "import sq\nprint(sq.square(4)",
    "files: [
        {"filename": "sq.py": "contents": "def square(x): return x*x"}
    ],
    "environment": {
        "DATABASE_URL": "postgres://...."
    },
    "code_filename": "main.py", 
    "command": ["python", "main.py"],
    "timeout": 2.5
}
---
200 OK

{
    "exit_status": 0,
    "output": ""
}

It allows adding other files, setting environment variables before executing the code, and also customize what file to execute.

For example to run tests against given code:

POST /sessions
{
    "runtime": "python",
    "code": "def square(x): return x*x",
    "files: [
        {"filename": "test_sq.py": "contents": "..."},
        {"filename": "runtests.sh": "contents": "..."}
    ],
    "environment": {
        "DATABASE_URL": "postgres://...."
    },
    "filename": "sq.py",
    "command": ["python", "main.py"],
    "timeout": 2.5
}
---
200 OK

{
    "exit_status": 0,
    "output": "..."
}

The contents of files in the requests will be:

test_sq.py

from sq import square

def test_square_0():
     assert square(0) == 0

def test_square_4():
     assert square(4) == 16

runtests.sh

#! /bin/bash
export HOME=/tmp/home
mkdir -p $HOME
pip install pytest --user

# TODO return the results as JSON
pytest test_sq.py
Clone this wiki locally