Skip to content

Commit 276b9cb

Browse files
committed
nits: Migrate to case when
1 parent df7915c commit 276b9cb

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

_tools/ruby_h_to_go/lib/ruby_h_to_go/function_definition.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def generate_go_content
6363
args.each do |c_arg|
6464
case c_arg.pointer
6565
when :ref
66-
if c_arg.type == "char"
66+
case c_arg.type
67+
when "char"
68+
# c_arg is string
6769
if char_var_count >= 2
6870
char_var_name = "char#{snake_to_camel(c_arg.go_name)}"
6971
clean_var_name = "cleanChar#{c_arg.go_name}"
@@ -77,18 +79,17 @@ def generate_go_content
7779
go_function_lines << ""
7880

7981
casted_go_args << char_var_name.to_s
82+
when "void"
83+
# c_arg is pointer
84+
casted_go_args << c_arg.go_name
8085
else
81-
if c_arg.type == "void"
82-
casted_go_args << c_arg.go_name
83-
else
84-
c_var_name = "c#{snake_to_camel(c_arg.go_name)}"
86+
c_var_name = "c#{snake_to_camel(c_arg.go_name)}"
8587

86-
before_call_function_lines << "var #{c_var_name} #{cast_to_cgo_type(c_arg.type)}"
87-
after_call_function_lines <<
88-
"*#{c_arg.go_name} = #{ruby_c_type_to_go_type(c_arg.type, pos: :arg)}(#{c_var_name})"
88+
before_call_function_lines << "var #{c_var_name} #{cast_to_cgo_type(c_arg.type)}"
89+
after_call_function_lines <<
90+
"*#{c_arg.go_name} = #{ruby_c_type_to_go_type(c_arg.type, pos: :arg)}(#{c_var_name})"
8991

90-
casted_go_args << "&#{c_var_name}"
91-
end
92+
casted_go_args << "&#{c_var_name}"
9293
end
9394
when :function
9495
casted_go_args << "toCFunctionPointer(#{c_arg.go_name})"

0 commit comments

Comments
 (0)