Skip to content

Instantly share code, notes, and snippets.

@agrif
Created November 12, 2011 05:42
Show Gist options
  • Save agrif/1360101 to your computer and use it in GitHub Desktop.
Save agrif/1360101 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import ctypes
import ctypes.util
rs = ctypes.CDLL("libredstone.dylib")
c = ctypes.CDLL(ctypes.util.find_library("c"))
c.fdopen.restype = ctypes.c_void_p
c.fdopen.argtypes = [ctypes.c_int, ctypes.c_char_p]
c.fclose.restype = None
c.fclose.argtypes = [ctypes.c_void_p]
class CFile(object):
def __init__(self, f):
self._as_parameter_ = c.fdopen(f.fileno(), f.mode)
def __del__(self):
if not c is None:
c.fclose(self._as_parameter_)
rs.rs_nbt_parse_from_file.restype = ctypes.c_void_p
rs.rs_nbt_parse_from_file.argtypes = [ctypes.c_char_p]
rs.rs_nbt_get_root.restype = ctypes.c_void_p
rs.rs_nbt_get_root.argtypes = [ctypes.c_void_p]
rs.rs_tag_pretty_print.restype = None
rs.rs_tag_pretty_print.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
import sys
out = CFile(sys.stdout)
print out
nbt = rs.rs_nbt_parse_from_file("local/level.dat")
print nbt
root = rs.rs_nbt_get_root(nbt)
print root
rs.rs_tag_pretty_print(root, out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment