Skip to content

Commit

Permalink
generate and save a string defining the struct timeval as a FFI struct
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckremes committed Sep 30, 2015
1 parent 9a852dd commit 056ae04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions library/ffi/generators/structures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ def write_config(io)
@fields.each { |field| io.puts field.to_config(@name) }
end

def write_class(io)
layout = generate_layout.gsub(/\n/, '').squeeze(' ')
struct_name = @struct_name.split(' ').last.capitalize + "_t"
struct_class = "class #{struct_name} < FFI::Struct; #{layout}; end"

io.puts "rbx.platform.#{@name}.class = #{struct_class}"
end

def generate_layout
buf = ""

Expand Down
2 changes: 1 addition & 1 deletion rakelib/platform.rake
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ file 'runtime/platform.conf' => deps do |task|
s.name 'struct timeval'
s.field :tv_sec, :time_t
s.field :tv_usec, :suseconds_t
end.write_config(f)
end.tap { |struct| struct.write_config(f); struct.write_class(f) }

Rubinius::FFI::Generators::Structures.new 'sockaddr_in' do |s|
if BUILD_CONFIG[:windows]
Expand Down

0 comments on commit 056ae04

Please sign in to comment.