import ctypes
import os
import ffi_types
from python_ffi import Yamlate
if os.uname()[0] == 'Darwin':
lib = ctypes.cdll.LoadLibrary('../target/release/libyamlate.dylib')
else:
lib = ctypes.cdll.LoadLibrary('../target/release/libyamlate.so')
yamlate = Yamlate(lib)
with yamlate.new_environment() as environment:
environment.set_integer('hello', 2)
environment.set_string('world', 'blah')
environment.set_decimal('blah', 3.14)
print 'Environment value for \'world\':', environment.get_string('world')
print 'Environment value for \'hello\':', environment.get_integer('hello')
print 'Environment value for \'blah\':', environment.get_decimal('blah')
with open('../examples/example.yaml', 'r') as yaml_file:
data = yaml_file.read()
with yamlate.new_yaml_from_str(data) as root_yaml:
with root_yaml.hash_get('blah') as blah_yaml:
print 'Blah\'s type:', ffi_types.yaml_type_to_str(blah_yaml.type())
print 'Blah\'s value:', blah_yaml.get_integer()
with root_yaml.hash_get('foo') as foo_yaml:
print 'Foo\'s type:', ffi_types.yaml_type_to_str(foo_yaml.type())
print 'Foo array length:', foo_yaml.array_len()
with foo_yaml.array_get(0) as sub_yaml:
print 'Foo\'s first array element type:', ffi_types.yaml_type_to_str(sub_yaml.type())
with foo_yaml.evaluate(environment) as result:
print 'Foo\'s value:', result.get_integer()
print 'Root\'s type:', ffi_types.yaml_type_to_str(root_yaml.type())
print 'Root keys:', root_yaml.hash_keys()