"""PyO2Bas - a Python module that wrap Oxygen"""
import ctypes
MODE_ASCIIZ = 0
class Error(Exception):
"""pyo2bas generic exception."""
def __init__(self, s):
Exception.__init__(self, s)
class O2bas(object):
"""Oxygen wrapper class."""
def __init__(self):
"""Initialize the library and its functions."""
try:
self.dll = ctypes.WinDLL("oxygen.dll")
except:
raise Error("Can't load oxygen.dll!")
INT, PCHAR = ctypes.c_int, ctypes.c_char_p
self._o2_mode = self._get_proc("o2_mode", None, [INT])
self._o2_asmo = self._get_proc("o2_asmo", None, [PCHAR])
self._o2_basic = self._get_proc("o2_basic", None, [PCHAR])
self._o2_error = self._get_proc("o2_error", PCHAR, [])
self._o2_exec = self._get_proc("o2_exec", INT, [INT])
self._o2_mode(MODE_ASCIIZ)
def _get_proc(self, name, ret, args):
"""Helper to set the various functions parameters & ret values."""
func = self.dll[name]
func.restype = ret
func.argtypes = args
return func
def geterror(self):
"""Return an error string from Oxygen."""
res = self._o2_error()
if res:
return res
else:
return ""
def asm(self, code):
"""Compile Assembly code."""
self._o2_asmo(code)
def basic(self, code):
"""Compile BASIC code."""
self._o2_basic(code)
def execute(self):
"""Execute compiled code."""
return self._o2_exec(0)