PyLua V0.2
Features
- Bytecode Compilation: Compile Python code once, execute multiple times
- Python Syntax: Almost full support for all Python variables, operators, control flow, and data structures
- Data Structures: Lists, dictionaries, tuples, sets with proper Python semantics
- Control Flow: if/elif/else, for loops, while loops with nested support
- Built-ins: print(), len(), type(), range(), int(), float(), str(), bool()
- Optimized VM: Stack-based virtual machine for efficient bytecode execution
Basic Usage
local python = require('path.to.PyLua0.2.python')
-- Simple one-line execution
python.execute('print("Hello, PyLua 0.2!")')Compile Once, Execute Multiple Times
For better performance when running the same code repeatedly:
local python = require('path.to.PyLua0.2.python')
-- Compile Python code to bytecode
local bytecode, error = python.compile([[
x = 10
y = 20
result = x + y
print("Result:", result)
]])
if error then
print("Compilation error:", error)
return
end
-- Execute the bytecode multiple times
for i = 1, 5 do
print("Execution", i)
local success, variables = python.runBytecode(bytecode)
if success then
print("Variables:", variables)
end
end