<% 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 %>