Marek Kubica avatar Marek Kubica committed 1677d24

Added code to actually run stuff in Ghostscript

Comments (0)

Files changed (2)

+#!/usr/bin/env python3
+"""Ghostscript utilities, like GLu, but better!"""
+from ctypes import c_int, pointer
+import libgs
+CHUNK_SIZE = 65535
+def run_code(instance, code):
+    exit_code = c_int()
+    codeseq = bytes(code, 'utf-8')
+    chunk = codeseq
+    libgs.gsapi_run_string_begin(instance, 0, pointer(exit_code))
+    while codeseq:
+        chunk = codeseq[:CHUNK_SIZE]
+        libgs.gsapi_run_string_continue(instance, chunk, len(chunk), 0, pointer(exit_code))
+        codeseq = codeseq[CHUNK_SIZE:]
+    libgs.gsapi_run_string_end(instance, 0, pointer(exit_code))
+def main():
+    code = "1 2 add == flush"
+    gs = libgs.gsapi_new_instance()
+    libgs.gsapi_init_with_args(gs, ['gs'])
+    run_code(gs, code)
+    print(gs)
+    libgs.gsapi_exit(gs)
+    libgs.gsapi_delete_instance(gs)
+if __name__ == '__main__':
+    main()
         raise GhostScriptException(
             'Initialization of instance failed')
+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
 gsapi_delete_instance = libgs.gsapi_delete_instance
 gsapi_exit = libgs.gsapi_exit
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.