Marek Kubica avatar Marek Kubica committed b558864

Made pushing undefined words possible

Comments (0)

Files changed (1)

 #/usr/bin/env python3
 """Ghostscript utilities toolkit, like GLut, but better!"""
+from functools import partial
 import libgs
 import gsu
                     # quiet out copyright messages and stuff
-        libgs.gsapi_set_stdio(gs, self._stdin_handler, self._stdout_handler,
-                self._stderr_handler)
+        #libgs.gsapi_set_stdio(gs, self._stdin_handler, self._stdout_handler,
+        #        self._stderr_handler)
         # save for later use
         self._instance = gs
     _stderr_handler = _stdout_handler
     def number(self, value):
-        gsu.run_code(self._instance, str(value))
+        """Pushes a number on the stack by converting into a string"""
+        return self.raw(str(value))
+    def raw(self, code):
+        """Runs raw PostScript code on the current instance"""
+        gsu.run_code(self._instance, code)
+        return self
     def __getattr__(self, name):
-        print("Pushing {0} on stack".format(name))
-        return self
+        """Returns a function that will push the value once called"""
+        return partial(self.raw, code=name)
 def main():
     gsi = GhostScriptInterpreter()
-    gsi.number(1)
+    gsi.number(1).number(2)
+    gsi.add().pstack()
 if __name__ == '__main__':
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.