Class: YAMLScript
- Inherits:
-
Object
- Object
- YAMLScript
- Defined in:
- lib/yamlscript.rb,
lib/yamlscript/version.rb
Overview
Ruby binding for the libyamlscript shared library.
Defined Under Namespace
Modules: LibYAMLScript
Constant Summary collapse
- Error =
Class.new(StandardError)
- YAMLSCRIPT_VERSION =
This value is automatically updated by ‘make bump’. The version number is used to find the correct shared library file. We currently only support binding to an exact version of libyamlscript.
'0.1.87'
- VERSION =
"0.1.87"
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.load(ys_code, **options) ⇒ Object
Interface with the libyamlscript shared library.
Instance Method Summary collapse
-
#initialize(**options) ⇒ YAMLScript
constructor
A new instance of YAMLScript.
-
#load(ys_code) ⇒ Object
Compile and eval a YAMLScript string and return the result.
Constructor Details
#initialize(**options) ⇒ YAMLScript
Returns a new instance of YAMLScript.
89 90 91 92 93 94 95 96 |
# File 'lib/yamlscript.rb', line 89 def initialize(**) # config not used yet @options = # Create a new GraalVM isolate for life of the YAMLScript instance @isolate = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP) @error = nil end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
87 88 89 |
# File 'lib/yamlscript.rb', line 87 def error @error end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
87 88 89 |
# File 'lib/yamlscript.rb', line 87 def @options end |
Class Method Details
.load(ys_code, **options) ⇒ Object
Interface with the libyamlscript shared library.
83 84 85 |
# File 'lib/yamlscript.rb', line 83 def self.load(ys_code, **) new(**).load(ys_code) end |
Instance Method Details
#load(ys_code) ⇒ Object
Compile and eval a YAMLScript string and return the result
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/yamlscript.rb', line 99 def load(ys_code) # Create a new GraalVM isolate thread for each call to load() thread = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP) raise Error, "Failed to create isolate" unless \ LibYAMLScript.graal_create_isolate(nil, @isolate.ref, thread.ref).zero? # Call 'load_ys_to_json' function in libyamlscript shared library json_data = LibYAMLScript.load_ys_to_json(thread, ys_code) resp = JSON.parse(json_data.to_s) raise Error, "Failed to tear down isolate" unless \ LibYAMLScript.graal_tear_down_isolate(thread).zero? raise Error, @error['cause'] if @error = resp['error'] data = resp.fetch('data') do raise Error, "Unexpected response from 'libyamlscript'" end data end |