libui 0.1.3.pre-x64-mingw32 → 0.2.0.pre-x64-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +275 -251
- data/lib/libui/error.rb +10 -0
- data/lib/libui/ffi.rb +658 -647
- data/lib/libui/fiddle_patch.rb +87 -87
- data/lib/libui/libui_base.rb +52 -52
- data/lib/libui/utils.rb +19 -19
- data/lib/libui/version.rb +3 -3
- data/lib/libui.rb +268 -258
- data/vendor/LICENSE.md +10 -10
- data/vendor/README.md +157 -157
- data/vendor/libui.x64.dll +0 -0
- metadata +19 -4
data/lib/libui/fiddle_patch.rb
CHANGED
@@ -1,87 +1,87 @@
|
|
1
|
-
module LibUI
|
2
|
-
# This module overrides Fiddle's mtehods
|
3
|
-
# - Fiddle::Importer#extern
|
4
|
-
# - Fiddle::CParser#parse_signature
|
5
|
-
# Original methods are in
|
6
|
-
# - https://github.com/ruby/fiddle/blob/master/lib/fiddle/import.rb
|
7
|
-
# - https://github.com/ruby/fiddle/blob/master/lib/fiddle/cparser.rb
|
8
|
-
# These changes add the ability to parse the signatures of functions given as arguments.
|
9
|
-
|
10
|
-
module FiddlePatch
|
11
|
-
def parse_signature(signature, tymap = nil)
|
12
|
-
tymap ||= {}
|
13
|
-
ctype, func, args = case compact(signature)
|
14
|
-
when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/
|
15
|
-
[TYPE_VOIDP, Regexp.last_match(1), Regexp.last_match(2)]
|
16
|
-
when /^([\w\*\s]+[*\s])(\w+)\((.*?)\);?$/
|
17
|
-
[parse_ctype(Regexp.last_match(1).strip, tymap), Regexp.last_match(2), Regexp.last_match(3)]
|
18
|
-
else
|
19
|
-
raise("can't parserake the function prototype: #{signature}")
|
20
|
-
end
|
21
|
-
symname = func
|
22
|
-
callback_argument_types = {} # Added
|
23
|
-
argtype = split_arguments(args).collect.with_index do |arg, idx| # Added with_index
|
24
|
-
# Check if it is a function pointer or not
|
25
|
-
if arg =~ /\(\*.*\)\(.*\)/ # Added
|
26
|
-
# From the arguments, create a notation that looks like a function declaration
|
27
|
-
# int(*f)(int *, void *) -> int f(int *, void *)
|
28
|
-
func_arg = arg.sub('(*', ' ').sub(')', '') # Added
|
29
|
-
# Use Fiddle's parse_signature method again.
|
30
|
-
callback_argument_types[idx] = parse_signature(func_arg) # Added
|
31
|
-
end
|
32
|
-
parse_ctype(arg, tymap)
|
33
|
-
end
|
34
|
-
# Added callback_argument_types. Original method return only 3 values.
|
35
|
-
[symname, ctype, argtype, callback_argument_types]
|
36
|
-
end
|
37
|
-
|
38
|
-
def extern(signature, *opts)
|
39
|
-
symname, ctype, argtype, callback_argument_types = parse_signature(signature, type_alias)
|
40
|
-
opt = parse_bind_options(opts)
|
41
|
-
func = import_function(symname, ctype, argtype, opt[:call_type])
|
42
|
-
|
43
|
-
# callback_argument_types
|
44
|
-
func.instance_variable_set(:@callback_argument_types,
|
45
|
-
callback_argument_types) # Added
|
46
|
-
# attr_reader
|
47
|
-
def func.callback_argument_types
|
48
|
-
@callback_argument_types
|
49
|
-
end
|
50
|
-
|
51
|
-
# argument_types
|
52
|
-
# Ruby 2.7 Fiddle::Function dose not have @argument_types
|
53
|
-
# Ruby 3.0 Fiddle::Function has @argument_types
|
54
|
-
if func.instance_variable_defined?(:@argument_types)
|
55
|
-
# check if @argument_types are the same
|
56
|
-
if func.instance_variable_get(:@argument_types) != argtype
|
57
|
-
warn "#{symname} func.argument_types:#{func.argument_types} != argtype #{argtype}"
|
58
|
-
end
|
59
|
-
else
|
60
|
-
func.instance_variable_set(:@argument_types, argtype)
|
61
|
-
end
|
62
|
-
# attr_reader
|
63
|
-
def func.argument_types
|
64
|
-
@argument_types
|
65
|
-
end
|
66
|
-
|
67
|
-
name = symname.gsub(/@.+/, '')
|
68
|
-
@func_map[name] = func
|
69
|
-
# define_method(name){|*args,&block| f.call(*args,&block)}
|
70
|
-
begin
|
71
|
-
/^(.+?):(\d+)/ =~ caller.first
|
72
|
-
file = Regexp.last_match(1)
|
73
|
-
line = Regexp.last_match(2).to_i
|
74
|
-
rescue StandardError
|
75
|
-
file, line = __FILE__, __LINE__ + 3
|
76
|
-
end
|
77
|
-
module_eval(<<-EOS, file, line)
|
78
|
-
def #{name}(*args, &block)
|
79
|
-
@func_map['#{name}'].call(*args,&block)
|
80
|
-
end
|
81
|
-
EOS
|
82
|
-
module_function(name)
|
83
|
-
func
|
84
|
-
end
|
85
|
-
end
|
86
|
-
private_constant :FiddlePatch
|
87
|
-
end
|
1
|
+
module LibUI
|
2
|
+
# This module overrides Fiddle's mtehods
|
3
|
+
# - Fiddle::Importer#extern
|
4
|
+
# - Fiddle::CParser#parse_signature
|
5
|
+
# Original methods are in
|
6
|
+
# - https://github.com/ruby/fiddle/blob/master/lib/fiddle/import.rb
|
7
|
+
# - https://github.com/ruby/fiddle/blob/master/lib/fiddle/cparser.rb
|
8
|
+
# These changes add the ability to parse the signatures of functions given as arguments.
|
9
|
+
|
10
|
+
module FiddlePatch
|
11
|
+
def parse_signature(signature, tymap = nil)
|
12
|
+
tymap ||= {}
|
13
|
+
ctype, func, args = case compact(signature)
|
14
|
+
when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/
|
15
|
+
[TYPE_VOIDP, Regexp.last_match(1), Regexp.last_match(2)]
|
16
|
+
when /^([\w\*\s]+[*\s])(\w+)\((.*?)\);?$/
|
17
|
+
[parse_ctype(Regexp.last_match(1).strip, tymap), Regexp.last_match(2), Regexp.last_match(3)]
|
18
|
+
else
|
19
|
+
raise("can't parserake the function prototype: #{signature}")
|
20
|
+
end
|
21
|
+
symname = func
|
22
|
+
callback_argument_types = {} # Added
|
23
|
+
argtype = split_arguments(args).collect.with_index do |arg, idx| # Added with_index
|
24
|
+
# Check if it is a function pointer or not
|
25
|
+
if arg =~ /\(\*.*\)\(.*\)/ # Added
|
26
|
+
# From the arguments, create a notation that looks like a function declaration
|
27
|
+
# int(*f)(int *, void *) -> int f(int *, void *)
|
28
|
+
func_arg = arg.sub('(*', ' ').sub(')', '') # Added
|
29
|
+
# Use Fiddle's parse_signature method again.
|
30
|
+
callback_argument_types[idx] = parse_signature(func_arg) # Added
|
31
|
+
end
|
32
|
+
parse_ctype(arg, tymap)
|
33
|
+
end
|
34
|
+
# Added callback_argument_types. Original method return only 3 values.
|
35
|
+
[symname, ctype, argtype, callback_argument_types]
|
36
|
+
end
|
37
|
+
|
38
|
+
def extern(signature, *opts)
|
39
|
+
symname, ctype, argtype, callback_argument_types = parse_signature(signature, type_alias)
|
40
|
+
opt = parse_bind_options(opts)
|
41
|
+
func = import_function(symname, ctype, argtype, opt[:call_type])
|
42
|
+
|
43
|
+
# callback_argument_types
|
44
|
+
func.instance_variable_set(:@callback_argument_types,
|
45
|
+
callback_argument_types) # Added
|
46
|
+
# attr_reader
|
47
|
+
def func.callback_argument_types
|
48
|
+
@callback_argument_types
|
49
|
+
end
|
50
|
+
|
51
|
+
# argument_types
|
52
|
+
# Ruby 2.7 Fiddle::Function dose not have @argument_types
|
53
|
+
# Ruby 3.0 Fiddle::Function has @argument_types
|
54
|
+
if func.instance_variable_defined?(:@argument_types)
|
55
|
+
# check if @argument_types are the same
|
56
|
+
if func.instance_variable_get(:@argument_types) != argtype
|
57
|
+
warn "#{symname} func.argument_types:#{func.argument_types} != argtype #{argtype}"
|
58
|
+
end
|
59
|
+
else
|
60
|
+
func.instance_variable_set(:@argument_types, argtype)
|
61
|
+
end
|
62
|
+
# attr_reader
|
63
|
+
def func.argument_types
|
64
|
+
@argument_types
|
65
|
+
end
|
66
|
+
|
67
|
+
name = symname.gsub(/@.+/, '')
|
68
|
+
@func_map[name] = func
|
69
|
+
# define_method(name){|*args,&block| f.call(*args,&block)}
|
70
|
+
begin
|
71
|
+
/^(.+?):(\d+)/ =~ caller.first
|
72
|
+
file = Regexp.last_match(1)
|
73
|
+
line = Regexp.last_match(2).to_i
|
74
|
+
rescue StandardError
|
75
|
+
file, line = __FILE__, __LINE__ + 3
|
76
|
+
end
|
77
|
+
module_eval(<<-EOS, file, line)
|
78
|
+
def #{name}(*args, &block)
|
79
|
+
@func_map['#{name}'].call(*args,&block)
|
80
|
+
end
|
81
|
+
EOS
|
82
|
+
module_function(name)
|
83
|
+
func
|
84
|
+
end
|
85
|
+
end
|
86
|
+
private_constant :FiddlePatch
|
87
|
+
end
|
data/lib/libui/libui_base.rb
CHANGED
@@ -1,52 +1,52 @@
|
|
1
|
-
module LibUI
|
2
|
-
module LibUIBase
|
3
|
-
FFI.func_map.each_key do |original_method_name|
|
4
|
-
name = Utils.convert_to_ruby_method(original_method_name)
|
5
|
-
func = FFI.func_map[original_method_name]
|
6
|
-
|
7
|
-
define_method(name) do |*args, &blk|
|
8
|
-
# Assume that block is the last argument.
|
9
|
-
args << blk if blk
|
10
|
-
|
11
|
-
# The proc object is converted to a Closure::BlockCaller object.
|
12
|
-
args.map!.with_index do |arg, idx|
|
13
|
-
next arg unless arg.is_a?(Proc)
|
14
|
-
|
15
|
-
# now arg must be Proc
|
16
|
-
|
17
|
-
# The types of the function arguments are stored in advance.
|
18
|
-
# See the monkey patch in ffi.rb.
|
19
|
-
_f, ret_type, arg_types = func.callback_argument_types[idx]
|
20
|
-
# TODO: raise some nice error if _f is nil.
|
21
|
-
|
22
|
-
callback = Fiddle::Closure::BlockCaller.new(
|
23
|
-
ret_type, arg_types, &arg
|
24
|
-
)
|
25
|
-
# Protect from GC
|
26
|
-
# by giving the owner object a reference to the callback.
|
27
|
-
# See https://github.com/kojix2/LibUI/issues/8
|
28
|
-
owner = if idx == 0 or # UI.queue_main{}
|
29
|
-
owner.frozen? # UI.timer(100) {}
|
30
|
-
LibUIBase # or UI is better?
|
31
|
-
else
|
32
|
-
args[0] # receiver
|
33
|
-
end
|
34
|
-
if owner.instance_variable_defined?(:@callbacks)
|
35
|
-
owner.instance_variable_get(:@callbacks) << callback
|
36
|
-
else
|
37
|
-
owner.instance_variable_set(:@callbacks, [callback])
|
38
|
-
end
|
39
|
-
callback
|
40
|
-
end
|
41
|
-
|
42
|
-
# Make it possible to omit the last nil. This may be an over-optimization.
|
43
|
-
siz = func.argument_types.size - 1
|
44
|
-
args[siz] = nil if args.size == siz
|
45
|
-
|
46
|
-
FFI.public_send(original_method_name, *args)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
private_constant :LibUIBase
|
52
|
-
end
|
1
|
+
module LibUI
|
2
|
+
module LibUIBase
|
3
|
+
FFI.func_map.each_key do |original_method_name|
|
4
|
+
name = Utils.convert_to_ruby_method(original_method_name)
|
5
|
+
func = FFI.func_map[original_method_name]
|
6
|
+
|
7
|
+
define_method(name) do |*args, &blk|
|
8
|
+
# Assume that block is the last argument.
|
9
|
+
args << blk if blk
|
10
|
+
|
11
|
+
# The proc object is converted to a Closure::BlockCaller object.
|
12
|
+
args.map!.with_index do |arg, idx|
|
13
|
+
next arg unless arg.is_a?(Proc)
|
14
|
+
|
15
|
+
# now arg must be Proc
|
16
|
+
|
17
|
+
# The types of the function arguments are stored in advance.
|
18
|
+
# See the monkey patch in ffi.rb.
|
19
|
+
_f, ret_type, arg_types = func.callback_argument_types[idx]
|
20
|
+
# TODO: raise some nice error if _f is nil.
|
21
|
+
|
22
|
+
callback = Fiddle::Closure::BlockCaller.new(
|
23
|
+
ret_type, arg_types, &arg
|
24
|
+
)
|
25
|
+
# Protect from GC
|
26
|
+
# by giving the owner object a reference to the callback.
|
27
|
+
# See https://github.com/kojix2/LibUI/issues/8
|
28
|
+
owner = if idx == 0 or # UI.queue_main{}
|
29
|
+
owner.frozen? # UI.timer(100) {}
|
30
|
+
LibUIBase # or UI is better?
|
31
|
+
else
|
32
|
+
args[0] # receiver
|
33
|
+
end
|
34
|
+
if owner.instance_variable_defined?(:@callbacks)
|
35
|
+
owner.instance_variable_get(:@callbacks) << callback
|
36
|
+
else
|
37
|
+
owner.instance_variable_set(:@callbacks, [callback])
|
38
|
+
end
|
39
|
+
callback
|
40
|
+
end
|
41
|
+
|
42
|
+
# Make it possible to omit the last nil. This may be an over-optimization.
|
43
|
+
siz = func.argument_types.size - 1
|
44
|
+
args[siz] = nil if args.size == siz
|
45
|
+
|
46
|
+
FFI.public_send(original_method_name, *args)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private_constant :LibUIBase
|
52
|
+
end
|
data/lib/libui/utils.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
module LibUI
|
2
|
-
module Utils
|
3
|
-
class << self
|
4
|
-
def convert_to_ruby_method(original_method_name)
|
5
|
-
underscore(original_method_name.delete_prefix('ui'))
|
6
|
-
end
|
7
|
-
|
8
|
-
# Converting camel case to underscore case in ruby
|
9
|
-
# https://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby#1509939
|
10
|
-
def underscore(str)
|
11
|
-
str.gsub(/::/, '/') # Maybe we don't need it.
|
12
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
13
|
-
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
14
|
-
.tr('-', '_')
|
15
|
-
.downcase
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
1
|
+
module LibUI
|
2
|
+
module Utils
|
3
|
+
class << self
|
4
|
+
def convert_to_ruby_method(original_method_name)
|
5
|
+
underscore(original_method_name.delete_prefix('ui'))
|
6
|
+
end
|
7
|
+
|
8
|
+
# Converting camel case to underscore case in ruby
|
9
|
+
# https://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby#1509939
|
10
|
+
def underscore(str)
|
11
|
+
str.gsub(/::/, '/') # Maybe we don't need it.
|
12
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
13
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
14
|
+
.tr('-', '_')
|
15
|
+
.downcase
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/libui/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module LibUI
|
2
|
-
VERSION = '0.
|
3
|
-
end
|
1
|
+
module LibUI
|
2
|
+
VERSION = '0.2.0.pre'
|
3
|
+
end
|