Skip to content

Commit 83283ea

Browse files
committed
feat: implemented signal arguments
1 parent 5a485e7 commit 83283ea

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

src/class.v

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module gd
22

3+
const no_meta = GDExtensionClassMethodArgumentMetadata.gdextension_method_argument_metadata_none
4+
35
pub struct ClassInfo {
46
mut:
57
name string
@@ -170,7 +172,7 @@ const prop_map = {
170172

171173
fn get_property_type(typ string) GDExtensionVariantType {
172174
// TODO: make better
173-
return prop_map[typ.split('.').last()] or { return .type_nil }
175+
return prop_map[typ.split('.').last()] or { return .type_object }
174176
}
175177

176178
fn class_get_property_list[T](instance GDExtensionClassInstancePtr, return_count &u32) &GDExtensionPropertyInfo {
@@ -383,6 +385,34 @@ pub fn register_class_methods[T](mut ci ClassInfo) {
383385
if 'gd.expose' in method.attrs {
384386
method_data := method
385387
method_sn := StringName.new(method.name)
388+
389+
mut args_info := []GDExtensionPropertyInfo{}
390+
$for arg in method.params {
391+
// get proper type for this argument
392+
arg_class := StringName.new(typeof(arg.typ).name.split('.').last())
393+
arg_type := get_property_type(typeof(arg.typ).name)
394+
arg_name := StringName.new(arg.name)
395+
hint := String.new('hint_string')
396+
defer {
397+
arg_name.deinit()
398+
hint.deinit()
399+
}
400+
info := GDExtensionPropertyInfo{
401+
type_: arg_type
402+
name: &arg_name
403+
class_name: &arg_class
404+
hint: .property_hint_none
405+
hint_string: &hint
406+
usage: .property_usage_default
407+
}
408+
args_info << info
409+
}
410+
first_arg := if args_info.len > 0 {
411+
args_info.first()
412+
} else {
413+
GDExtensionPropertyInfo{}
414+
}
415+
386416
// TODO: fill out arg and return info
387417
info := GDExtensionClassMethodInfo{
388418
name: &method_sn
@@ -395,9 +425,9 @@ pub fn register_class_methods[T](mut ci ClassInfo) {
395425
has_return_value: GDExtensionBool(false)
396426
return_value_info: unsafe { nil }
397427
return_value_metadata: .gdextension_method_argument_metadata_none
398-
argument_count: 0
399-
arguments_info: unsafe { nil }
400-
arguments_metadata: unsafe { nil }
428+
argument_count: u32(method.args.len)
429+
arguments_info: &first_arg
430+
arguments_metadata: &no_meta
401431
default_argument_count: 0
402432
default_arguments: unsafe { nil }
403433
}
@@ -475,7 +505,7 @@ pub fn register_class_properties[T](mut ci ClassInfo) {
475505
return_value_metadata: .gdextension_method_argument_metadata_none
476506
argument_count: 0
477507
arguments_info: unsafe { nil }
478-
arguments_metadata: unsafe { nil }
508+
arguments_metadata: &no_meta
479509
default_argument_count: 0
480510
default_arguments: unsafe { nil }
481511
}
@@ -492,16 +522,6 @@ pub fn register_class_properties[T](mut ci ClassInfo) {
492522
if unsafe { arg_info_ptr == nil } {
493523
panic('Failed to allocate memory for arguments_info')
494524
}
495-
496-
// create the argument metadata
497-
setter_arg_metadata_size := int(sizeof(GDExtensionClassMethodArgumentMetadata))
498-
arg_metadata_ptr := unsafe { &GDExtensionClassMethodArgumentMetadata(C.malloc(setter_arg_metadata_size)) }
499-
if unsafe { arg_metadata_ptr == nil } {
500-
panic('Failed to allocate memory for arguments_metadata')
501-
}
502-
unsafe {
503-
*arg_metadata_ptr = .gdextension_method_argument_metadata_none
504-
}
505525
// we need a mutable version of GDExtensionPropertyInfo to set fields
506526
// since struct fields are immutable by default
507527
property_info := GDExtensionPropertyInfo{
@@ -530,7 +550,7 @@ pub fn register_class_properties[T](mut ci ClassInfo) {
530550
return_value_metadata: .gdextension_method_argument_metadata_none
531551
argument_count: 1
532552
arguments_info: arg_info_ptr
533-
arguments_metadata: arg_metadata_ptr
553+
arguments_metadata: &no_meta
534554
default_argument_count: 0
535555
default_arguments: unsafe { nil }
536556
}

src/generator/generator.v

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ fn (g &Generator) gen_functions() ! {
191191
| if method.name == method_data.name {
192192
| mut params := []voidptr{}
193193
| // handle params
194-
| // TODO: expand arg type coverage
195194
| // TODO: leverage `ToVariant` and `FromVariant` interfaces
196195
| mut p := 0
197196
| \$for param in method.params {
@@ -218,7 +217,7 @@ fn (g &Generator) gen_functions() ! {
218217
continue
219218
}
220219
buf.writeln('
221-
| } \$else \$if param.typ is &${class.name} {
220+
| } \$else \$if param.typ is ${class.name} || param.typ is &${class.name} {
222221
| mut value := ${class.name}{}
223222
| value.from_variant(prm)
224223
| params << &value
@@ -227,7 +226,7 @@ fn (g &Generator) gen_functions() ! {
227226

228227
for class in g.api.classes {
229228
buf.writeln('
230-
| } \$else \$if param.typ is &${class.name} {
229+
| } \$else \$if param.typ is ${class.name} || param.typ is &${class.name} {
231230
| mut value := ${class.name}{}
232231
| value.from_variant(prm)
233232
| params << &value

0 commit comments

Comments
 (0)