Skip to main content

A self-contained Cyber intepreter

Project description

cyberlang - batteries included python bindings for cyber

license pypi version PyPI status discord

Installation

pip install cyberlang

Usage

Simply create a CyberVM instance and evaluate a string:

from cyber import CyberVM

vm = CyberVM()
vm.eval("print 'hello world!'")

Want to capture printed output? Override the print function from Cyber's core module with a binding.

The decorator generates all the required wrappers and interfaces, and registers everything with Cyber's VM.

from cyber import CyberVM

vm = CyberVM()

@vm.function('core.print')
def _print(string: str):
    print(string)

vm.eval("print 'hello world!'")

Alternate techniques for creating callback functions:

# if no module, assume core
# same result as previous example
# this creates function "print2" in the "core" module
@cyber.function('print2')
def _print2(string: str):
    print(string)

# if no module, assume core
# if no function name, use existing function name
# this creates function "test" in the "core" module
@cyber.function
def test():
    print('core.test')

Or define multiple functions at once using this class-based syntax

# "core" already exists, so add a() and b() to it
class Core(cyber.module('core')):
    def a(self):
        print('core.test')
    def b(self):
        print('core.test2')

# create "new_module" and add c() and d() to it
@cyber.module('new_module')
class Module:
    def c(self):
        print('new_module.test')
    def d(self):
        print('new_module.test2')

# create module, implicitly named "NewModule" and add e() and f() to it
@cyber.module
class NewModule:
    def e(self):
        print('NewModule.test')
    def f(self):
        print('NewModule.test2')

Supporters

fubar - creator of the Cyber language

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

cyberlang-0.5.3.tar.gz (3.7 MB view hashes)

Uploaded Source

Built Distributions

cyberlang-0.5.3-py3-none-win_amd64.whl (961.1 kB view hashes)

Uploaded Python 3 Windows x86-64

cyberlang-0.5.3-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.musllinux_1_1_x86_64.whl (958.1 kB view hashes)

Uploaded Python 3 manylinux: glibc 2.12+ x86-64 musllinux: musl 1.1+ x86-64

cyberlang-0.5.3-py3-none-macosx_11_0_arm64.whl (954.6 kB view hashes)

Uploaded Python 3 macOS 11.0+ ARM64

cyberlang-0.5.3-py3-none-macosx_10_9_x86_64.whl (882.9 kB view hashes)

Uploaded Python 3 macOS 10.9+ x86-64

cyberlang-0.5.3-py3-none-any.whl (3.7 MB view hashes)

Uploaded Python 3

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