Skip to content

Commit bc99b7e

Browse files
committed
Add proper documentation to FFI::Generator and ::Task
1 parent 17e13e2 commit bc99b7e

2 files changed

Lines changed: 53 additions & 4 deletions

File tree

lib/ffi/tools/generator.rb

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,49 @@
33

44
module FFI
55

6-
# @private
6+
##
7+
# Generate files with C structs for FFI::Struct and C constants.
8+
#
9+
# == A simple example
10+
#
11+
# In file +zlib.rb.ffi+:
12+
# module Zlib
13+
# @@@
14+
# constants do |c|
15+
# c.include "zlib.h"
16+
# c.const :ZLIB_VERNUM
17+
# end
18+
# @@@
19+
#
20+
# class ZStream < FFI::Struct
21+
#
22+
# struct do |s|
23+
# s.name "struct z_stream_s"
24+
# s.include "zlib.h"
25+
#
26+
# s.field :next_in, :pointer
27+
# s.field :avail_in, :uint
28+
# s.field :total_in, :ulong
29+
# end
30+
# @@@
31+
# end
32+
# end
33+
#
34+
# Translate the file:
35+
# require "ffi/tools/generator"
36+
# FFI::Generator.new "zlib.rb.ffi", "zlib.rb"
37+
#
38+
# Generates the file +zlib.rb+ with constant values and offsets:
39+
# module Zlib
40+
# ZLIB_VERNUM = 4784
41+
#
42+
# class ZStream < FFI::Struct
43+
# layout :next_in, :pointer, 0,
44+
# :avail_in, :uint, 8,
45+
# :total_in, :ulong, 16
46+
# end
47+
#
48+
# @see FFI::Generator::Task for easy integration in a Rakefile
749
class Generator
850

951
def initialize(ffi_name, rb_name, options = {})

lib/ffi/tools/generator_task.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
require 'rake/tasklib'
44

55
##
6-
# Rake task that calculates C structs for FFI::Struct.
7-
8-
# @private
6+
# Add Rake tasks that generate files with C structs for FFI::Struct and C constants.
7+
#
8+
# @example a simple example for your Rakefile
9+
# require "ffi/tools/generator_task"
10+
# # Add a task to generate my_object.rb out of my_object.rb.ffi
11+
# FFI::Generator::Task.new ["my_object.rb"], cflags: "-I/usr/local/mylibrary"
12+
#
13+
# The generated files are also added to the 'clear' task.
14+
#
15+
# @see FFI::Generator for a description of the file content
916
class FFI::Generator::Task < Rake::TaskLib
1017

1118
def initialize(rb_names)

0 commit comments

Comments
 (0)