lib/dub/lua/function_gen.rb in dub-0.6.4 vs lib/dub/lua/function_gen.rb in dub-0.6.5
- old
+ new
@@ -25,17 +25,22 @@
'bool',
]
def initialize
load_erb
+ @custom_types = []
end
def template_path=(template_path)
@template_path = template_path
load_erb
end
+ def custom_type(regexp, &block)
+ @custom_types << [regexp, block]
+ end
+
# Produce bindings for a group of overloaded functions
def group(group)
@group = group
if @group.members
@group_template.result(binding)
@@ -208,10 +213,12 @@
# Get argument and verify type
# // luaL_argcheck could be better to report errors like "expected Mat"
def get_arg(arg, stack_pos)
type_def = "#{arg.create_type}#{arg.name}#{arg.array_suffix}"
- if arg.is_native?
+ if custom_type = @custom_types.detect {|reg,proc| type_def =~ reg}
+ custom_type[1].call(type_def, arg, stack_pos)
+ elsif arg.is_native?
if arg.is_pointer?
if arg.type == 'char'
type_def = "const #{type_def}" unless arg.is_const?
"#{type_def} = luaL_checkstring(L, #{stack_pos});"
else