MCPcopy Create free account
hub / github.com/Autodesk/AutomaticComponentToolkit / buildGoInitialize

Function buildGoInitialize

Source/buildbindinggo.go:388–430  ·  view source on GitHub ↗
(component ComponentDefinition, implw LanguageWriter)

Source from the content-addressed store, hash-verified

386}
387
388func buildGoInitialize(component ComponentDefinition, implw LanguageWriter) {
389 NameSpace := component.NameSpace
390 global := component.Global
391
392 implw.Writeln("func (implementation *%sImplementation) Initialize(DLLFileName string) error {", NameSpace)
393 implw.Writeln(" implementation.Initialized = false;")
394 implw.Writeln(" implementation.DLLHandle = 0;")
395 implw.Writeln("")
396 implw.Writeln(" dllHandle, err := syscall.LoadLibrary(DLLFileName);")
397 implw.Writeln(" if (err != nil) {")
398 implw.Writeln(" return err;")
399 implw.Writeln(" }")
400 implw.Writeln("")
401
402 for i := 0; i < len(component.Classes); i++ {
403 class := component.Classes[i]
404 for j := 0; j < len(class.Methods); j++ {
405 method := class.Methods[j]
406 functionName := fmt.Sprintf("%s_%s_%s", strings.ToLower(NameSpace), strings.ToLower(class.ClassName), strings.ToLower(method.MethodName))
407 implw.Writeln(" implementation.%s_%s_%s, err = syscall.GetProcAddress(dllHandle, \"%s\")", NameSpace, strings.ToLower(class.ClassName), strings.ToLower(method.MethodName), functionName)
408 implw.Writeln(" if (err != nil) {")
409 implw.Writeln(" return errors.New(\"Could not get function %s: \" + err.Error())", functionName)
410 implw.Writeln(" }")
411 implw.Writeln(" ")
412 }
413 }
414
415 for j := 0; j < len(global.Methods); j++ {
416 method := global.Methods[j]
417
418 functionName := fmt.Sprintf("%s_%s", strings.ToLower(NameSpace), strings.ToLower(method.MethodName))
419 implw.Writeln(" implementation.%s_%s, err = syscall.GetProcAddress(dllHandle, \"%s\")", NameSpace, strings.ToLower(method.MethodName), functionName)
420 implw.Writeln(" if (err != nil) {")
421 implw.Writeln(" return errors.New(\"Could not get function %s: \" + err.Error())", functionName)
422 implw.Writeln(" }")
423 implw.Writeln(" ")
424 }
425
426 implw.Writeln(" implementation.DLLHandle = dllHandle")
427 implw.Writeln(" implementation.Initialized = true")
428 implw.Writeln(" return nil")
429 implw.Writeln("}")
430}
431
432func buildGoCallFunction(component ComponentDefinition, implw LanguageWriter) {
433 NameSpace := component.NameSpace

Callers 1

buildGoWrapperFunction · 0.85

Calls 1

WritelnMethod · 0.80

Tested by

no test coverage detected