1// Package gmodule was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gmodule
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11)
12
13// Specifies the type of the module initialization function.
14// If a module contains a function named g_module_check_init() it is called
15// automatically when the module is loaded. It is passed the #GModule structure
16// and should return %NULL on success or a string describing the initialization
17// error.
18type ModuleCheckInit func(*Module) string
19
20// Specifies the type of the module function called when it is unloaded.
21// If a module contains a function named g_module_unload() it is called
22// automatically when the module is unloaded.
23// It is passed the #GModule structure.
24type ModuleUnload func(*Module)
25
26// The #GModule struct is an opaque data structure to represent a
27// [dynamically-loaded module](modules.html#dynamic-loading-of-modules).
28// It should only be accessed via the following functions.
29//
30// To ensure correct lock ordering, these functions must not be called from
31// global constructors (for example, those using GCC’s
32// `__attribute__((constructor))` attribute).
33type Module struct {
34 _ structs.HostLayout
35}
36
37func (x *Module) GoPointer() uintptr {
38 return uintptr(unsafe.Pointer(x))
39}
40
41var xModuleClose func(uintptr) bool
42
43// Closes a module.
44func (x *Module) Close() bool {
45
46 cret := xModuleClose(x.GoPointer())
47 return cret
48}
49
50var xModuleMakeResident func(uintptr)
51
52// Ensures that a module will never be unloaded.
53// Any future g_module_close() calls on the module will be ignored.
54func (x *Module) MakeResident() {
55
56 xModuleMakeResident(x.GoPointer())
57
58}
59
60var xModuleName func(uintptr) string
61
62// Returns the filename that the module was opened with.
63//
64// If @module refers to the application itself, "main" is returned.
65func (x *Module) Name() string {
66
67 cret := xModuleName(x.GoPointer())
68 return cret
69}
70
71var xModuleSymbol func(uintptr, string, *uintptr) bool
72
73// Gets a symbol pointer from a module, such as one exported
74// by %G_MODULE_EXPORT. Note that a valid symbol can be %NULL.
75func (x *Module) Symbol(SymbolNameVar string, SymbolVar *uintptr) bool {
76
77 cret := xModuleSymbol(x.GoPointer(), SymbolNameVar, SymbolVar)
78 return cret
79}
80
81// Flags passed to g_module_open().
82// Note that these flags are not supported on all platforms.
83type ModuleFlags int
84
85const (
86
87 // specifies that symbols are only resolved when
88 // needed. The default action is to bind all symbols when the module
89 // is loaded.
90 GModuleBindLazyValue ModuleFlags = 1
91 // specifies that symbols in the module should
92 // not be added to the global name space. The default action on most
93 // platforms is to place symbols in the module in the global name space,
94 // which may cause conflicts with existing symbols.
95 GModuleBindLocalValue ModuleFlags = 2
96 // mask for all flags.
97 GModuleBindMaskValue ModuleFlags = 3
98)
99
100// Errors returned by g_module_open_full().
101type ModuleError int
102
103const (
104
105 // there was an error loading or opening a module file
106 GModuleErrorFailedValue ModuleError = 0
107 // a module returned an error from its `g_module_check_init()` function
108 GModuleErrorCheckFailedValue ModuleError = 1
109)
110
111var xModuleBuildPath func(uintptr, string) string
112
113// A portable way to build the filename of a module. The platform-specific
114// prefix and suffix are added to the filename, if needed, and the result
115// is added to the directory, using the correct separator character.
116//
117// The directory should specify the directory where the module can be found.
118// It can be %NULL or an empty string to indicate that the module is in a
119// standard platform-specific directory, though this is not recommended
120// since the wrong module may be found.
121//
122// For example, calling g_module_build_path() on a Linux system with a
123// @directory of `/lib` and a @module_name of "mylibrary" will return
124// `/lib/libmylibrary.so`. On a Windows system, using `\Windows` as the
125// directory it will return `\Windows\mylibrary.dll`.
126func ModuleBuildPath(DirectoryVar *string, ModuleNameVar string) string {
127
128 DirectoryVarPtr := core.GStrdupNullable(DirectoryVar)
129 defer core.GFreeNullable(DirectoryVarPtr)
130
131 cret := xModuleBuildPath(DirectoryVarPtr, ModuleNameVar)
132 return cret
133}
134
135var xNewModuleError func() string
136
137// Gets a string describing the last module error.
138func NewModuleError() string {
139
140 cret := xNewModuleError()
141 return cret
142}
143
144var xModuleSupported func() bool
145
146// Checks if modules are supported on the current platform.
147func ModuleSupported() bool {
148
149 cret := xModuleSupported()
150 return cret
151}
152
153func init() {
154 core.SetPackageName("GMODULE", "gmodule-2.0")
155 core.SetSharedLibraries("GMODULE", []string{"libgmodule-2.0.so.0"})
156 var libs []uintptr
157 for _, libPath := range core.GetPaths("GMODULE") {
158 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
159 if err != nil {
160 panic(err)
161 }
162 libs = append(libs, lib)
163 }
164
165 core.PuregoSafeRegister(&xModuleBuildPath, libs, "g_module_build_path")
166 core.PuregoSafeRegister(&xNewModuleError, libs, "g_module_error")
167 core.PuregoSafeRegister(&xModuleSupported, libs, "g_module_supported")
168
169 core.PuregoSafeRegister(&xModuleClose, libs, "g_module_close")
170 core.PuregoSafeRegister(&xModuleMakeResident, libs, "g_module_make_resident")
171 core.PuregoSafeRegister(&xModuleName, libs, "g_module_name")
172 core.PuregoSafeRegister(&xModuleSymbol, libs, "g_module_symbol")
173
174}