Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add enum literalization

  • Loading branch information...
commit b2c517b8b4984f4f55812d5024cfe5d968f53c8f 1 parent e4e64d0
@dlee authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 lib/ffickle.rb
View
14 lib/ffickle.rb
@@ -7,6 +7,8 @@ module FFIckle
CONTAINER_TYPES = [C::Struct, C::Union]
module Helper
+ attr_reader :typedef_map, :required_containers, :required_enums
+
def filepath_to_module_name(filepath)
File.basename(filepath, '.*').underscore.camelize.gsub('.', '_')
end
@@ -17,8 +19,7 @@ class ParseError < ::StandardError; end
class Library
include Helper
- attr_reader :files, :typedef_map, :module_name,
- :required_containers, :required_enums
+ attr_reader :files, :module_name
def initialize(lib, files)
@lib = lib
@@ -130,9 +131,16 @@ def ffi_struct_literal(struct, functions)
def ffi_enums_literal
@required_enums.map do |enum, functions|
+ literal = enum.members.map do |member|
+ if member.val
+ " :#{member.name}, #{member.val.val}"
+ else
+ " :#{member.name}"
+ end
+ end.join(",\n")
functions.uniq.map do |func|
" # required by #{func}()"
- end.join("\n") + "\n #{enum.name.camelize} = enum()"
+ end.join("\n") + "\n #{enum.name.camelize} = enum(\n#{literal}\n )"
end.join("\n")
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.