Sha256: 3c23f57a16e13e5a26e87111536ac6f456644f9633d06cb54081bb12132b280f

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

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

<% end %>
import ctypes, ctypes.util
<% for library in @libraries %>
<% if library && @functions[library] %>

<%= library&.name || :lib %> = ctypes.CDLL(
<% self.dlopen_paths_for(library).each_with_index do |library_path, i| %>
    <%= i.nonzero? ? 'or ' : '' %>ctypes.util.find_library("<%= library_path %>")
<% end %>
<% if !options[:library_path] && library&.dlopen %>
    or "<%= library.dlopen.first %>"
<% end %>
)
<% end %>
<% for enum in @enums[library] || [] %>

<% if enum.comment %>
# <%= enum.comment %>
<% end %>
<%= enum.name %> = ctypes.c_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 %> = ctypes.POINTER(ctypes.c_void)
<% else %>
class <%= struct.name %>(Structure):
  <% if struct.fields.nil? || struct.fields.empty? %>
    _fields_ = []
  <% else %>
    _fields_ = [
    <% for name, type in struct.fields || {} %>
        (<%= name.to_s.inspect %>, <%= struct_type(type) %>),  # <%= type %>
    <% end %>
    ]
  <% end %>
<% end %>
<% end %>
<% for function in @functions[library] || [] %>

<% if function.comment %>
# <%= function.comment %>
<% end %>
<%= function.name %> = <%= library&.name || :lib %>.<%= function.name %>
<%= function.name %>.restype = <%= param_type(function.type) %>
<%= function.name %>.argtypes = [<%=
  function.parameters.each_value.map { |p| param_type(p.type) }.join(', ')
%>]
<% end %>
<% end %>

Version data entries

1 entries across 1 versions & 1 rubygems

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