Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/uyjulian/pytjs

TJS2 bindings to Python
https://github.com/uyjulian/pytjs

Last synced: 6 days ago
JSON representation

TJS2 bindings to Python

Awesome Lists containing this project

README

        

# pytjs

## About

This repository contains a Python interface to TJS2.

## Installation (from PyPI)

```bash
python3 -m pip install pytjs
```

## Installation (from source)

First, clone this repository, including all submodules.
```bash
git clone --recursive https://github.com/uyjulian/pytjs.git
```
Now, you can run `pip install` on the repository path.
```bash
python3 -m pip install ./pytjs
```

## Usage

Firstly, you need to initialize a TJS script engine.
```py
import pytjs

ScriptEngine = pytjs.tTJS()
```
You can then get things in its global environment.
```py
ScriptEngineGlobal = ScriptEngine.GetGlobal()
print(ScriptEngineGlobal.Dictionary) #
# or
print(ScriptEngineGlobal['Dictionary']) #
```
You can also set values in the global environment.
```py
ScriptEngineGlobal = ScriptEngine.GetGlobal()
ScriptEngineGlobal.test = "test"
# or
ScriptEngineGlobal["test"] = "test"
```
You can evaluate expressions in the script engine environment.
```py
print(ScriptEngine.EvalExpression("123")) # 123
# 123
```
You can iterate through Array and Dictionary objects.
```py
arr = ScriptEngine.EvalExpression("['test', 'test2']")
for v in arr:
print(v)
# test
# test2
dic = ScriptEngine.EvalExpression("%['test' => 'test2']")
for v in dic:
print(v, dic[v])
# test
# test2
```

## License

This project is licensed under the MIT license. Please read the `LICENSE` file for more information.