Skip to main content

A customizable interpreted microlanguage designed to run untrusted code.

Project description

Scrolls

Scrolls is a small interpreter originally designed to allow users of my discord bots to make custom commands. It prioritizes control over the interpreter to help prevent abuse, while still allowing tight integration with python code.

Links

Why?

The two other candidates for user scripts were python and Lua. Python code is a nightmare to sandbox properly, and the available Lua interpreters for python didn't give me the kind of control I wanted over the interpreter. In addition, Lua was a bit much for simple custom commands. So, I made my own interpreter.

There is a scripting language available for Rust called Rhai with a similar concept.

Also, I just kinda wanted to try making an interpreted language...

Goals

  • Allow the developer to prevent abuse.
  • Integrate tightly with the parent python application.
  • Keep the syntax as simple as possible.

Getting Started

Check out the Links section above.

Installing

Scrolls may be installed through pip:

Linux

python3 -m pip install scrolls-py

Windows

py -3 -m pip install scrolls-py

Command Line Usage

The module comes with a built-in interpreter that may be invoked by executing the module. (Note that the linux version will be used from now on.)

python3 -m scrolls FILE

Try running some of the examples:

python3 -m scrolls ./examples/arithmetic.scrl

If no file is specified, the interpreter will run in interactive mode:

python3 -m scrolls

Programmatic Usage

Scrolls may be embedded into any python program:

import scrolls

# Create an interpreter. Note that an interpreter created this 
# way will not actually do anything. It's the responsibility of 
# the user to configure with the desired language features.
interpreter = scrolls.Interpreter()

# Configure the interpreter with the base language.
# scrolls.base_config is provided to make this common task
# a bit easier.
scrolls.base_config.configure(interpreter)

# Configure with stdio commands like input, and print
interpreter.command_handlers.add(scrolls.StdIoCommandHandler())

# Run your script.
script = """
print "Please enter your name:"
input name
!repeat(4) {
    print "Hello," $(cat $name "!")
}
"""
interpreter.run(script)

Acknowledgements

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrolls-py-0.2.0.tar.gz (43.3 kB view details)

Uploaded Source

Built Distribution

scrolls_py-0.2.0-py3-none-any.whl (44.9 kB view details)

Uploaded Python 3

File details

Details for the file scrolls-py-0.2.0.tar.gz.

File metadata

  • Download URL: scrolls-py-0.2.0.tar.gz
  • Upload date:
  • Size: 43.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.1

File hashes

Hashes for scrolls-py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ba3ea52d01c6c29a414f47347789ee59f787517c82c7838eb19ffa8f0799e9da
MD5 7c45061478cf03f96f7ea2d6c7bc1330
BLAKE2b-256 27df93e8c2b96cda1c5bad97508a3f56a6527eb4f9ebada76fa118fc6490d5d7

See more details on using hashes here.

File details

Details for the file scrolls_py-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: scrolls_py-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 44.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.1

File hashes

Hashes for scrolls_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d52d561132dcd9aa1243c36ea2a0599da5effa402f18374c0cd2b634d5a26bf
MD5 a0f8a2864e5c18c02ce79c4c62d46724
BLAKE2b-256 91fb033252a6f71826f69d18bb3600e86de6bf18f0915af5de75359f3fa8600f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page