Commits

Marek Kubica  committed 731309d

Added high level wrapper for libgs (GSut)

  • Participants
  • Parent commits 1677d24

Comments (0)

Files changed (2)

+#/usr/bin/env python3
+"""Ghostscript utilities toolkit, like GLut, but better!"""
+import libgs
+import gsu
+
+def std_stream_handler(f):
+    return libgs.c_stdstream_t(f)
+
+class GhostScriptInterpreter(object):
+    def __init__(self):
+        gs = libgs.gsapi_new_instance()
+        libgs.gsapi_init_with_args(gs, ['gs'])
+        libgs.gsapi_set_stdio(gs, self._stdin_handler, self._stdout_handler,
+                self._stderr_handler)
+        self._instance = gs
+
+    @std_stream_handler
+    def _stdout_handler(caller_handle, buf, length):
+        print(caller_handle, buf, length)
+        return 0
+
+    _stdin_handler = _stdout_handler
+    _stderr_handler = _stdout_handler
+
+def main():
+    gsi = GhostScriptInterpreter()
+
+if __name__ == '__main__':
+    main()
             ('revision', c_long),
             ('revisiondate', c_long)]
 
-c_stdstream_t = CFUNCTYPE(POINTER(c_int), c_void_p, c_char_p, c_int)
+c_stdstream_t = CFUNCTYPE(c_int, c_void_p, c_char_p, c_int)
 c_poll_t = CFUNCTYPE(POINTER(c_int), c_void_p)
 
 libgs = ctypes.CDLL(find_library('gs'))
 libgs.gsapi_delete_instance.restype = None
 libgs.gsapi_set_stdio.argtypes = (c_void_p, c_stdstream_t, c_stdstream_t, c_stdstream_t)
 libgs.gsapi_set_stdio.restype = c_int
-libgs.gsapi_set_stdio.argtypes = (c_void_p, c_poll_t)
 libgs.gsapi_set_poll.restype = c_int
 libgs.gsapi_set_poll.restype = c_int
 #libgs.gsapi_set_display_callback.argtypes = ()
         raise GhostScriptException(
             'Initialization of instance failed')
 
+gsapi_set_stdio = libgs.gsapi_set_stdio
 gsapi_run_string_begin = libgs.gsapi_run_string_begin
 gsapi_run_string_continue = libgs.gsapi_run_string_continue
 gsapi_run_string_end = libgs.gsapi_run_string_end