Sha256: 99724fd28fb93f2d8e0085f483037be71100f217dc9b7c9ca58b1aa3feeb7d31

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

<% if header? %>
# <%= FFIDB.header %>

<% end %>
require 'ffi'
<% for library in @libraries %>

module <%= options[:module] || library&.name&.capitalize || :FFI %>
<% if library && @functions[library] %>
  extend FFI::Library
  ffi_lib [<%= dlopen_paths_for(library).map(&:inspect).join(', ') %>]
<% end %>
<% for enum in @enums[library] || [] %>

  <% if enum.comment %>
  # <%= enum.comment %>
  <% end %>
  <%= enum.name %> = :int
  <% for name, value in enum.values || {} %>
  <%= name %> = <%= value %>
  <% end %>
<% end %>
<% for struct in @structs[library] || [] %>

  <% if struct.comment %>
  # <%= struct.comment %>
  <% end %>
  <% if struct.opaque? %>
  <%= struct.name %> = FFI::Pointer
  <% else %>
  class <%= struct.name %> < FFI::Struct
  <% for (name, type), i in (struct.fields || {}).each_with_index %>
    <%= i.zero? ? 'layout' : ' '*6 %> :<%= name %>, <%= struct_type(type).inspect %><%= (i == (struct.fields || {}).size-1) ? '' : ',' %>  # <%= type %>
  <% end %>
  end
  <% end %>
<% end %>
<% for function in @functions[library] || [] %>

  <% if function.comment %>
  # <%= function.comment %>
  <% end %>
  attach_function :<%= function.name %>, [<%=
    function.parameters.each_value.map { |p| param_type(p.type).inspect }.join(', ')
  %>], :<%= param_type(function.type) %>
<% end %>
end # <%= options[:module] || library&.name&.capitalize || :FFI %>
<% end %>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ffidb-0.12.0 etc/templates/ruby.erb