or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

categories.mdcore-bridge.mddecorators.mdframework-loading.mdindex.mdprotocols.mdtype-system.mdutilities.md

framework-loading.mddocs/

0

# Framework and Library Loading

1

2

Dynamic loading of macOS frameworks and libraries, bundle resource access, and framework initialization. These functions enable runtime access to system frameworks and custom libraries, allowing Python code to integrate with the full macOS ecosystem.

3

4

## Capabilities

5

6

### Dynamic Framework Loading

7

8

Functions for loading macOS frameworks at runtime.

9

10

```python { .api }

11

def dyld_framework(path: str):

12

"""

13

Load a framework from the specified path.

14

15

Args:

16

path (str): Full path to the framework bundle

17

18

Returns:

19

The loaded framework bundle object

20

21

Usage:

22

framework = objc.dyld_framework("/System/Library/Frameworks/AppKit.framework")

23

"""

24

25

def pathForFramework(name: str):

26

"""

27

Find the path to a framework by name.

28

29

Args:

30

name (str): Name of the framework (without .framework extension)

31

32

Returns:

33

str: Full path to the framework, or None if not found

34

35

Usage:

36

path = objc.pathForFramework("AppKit")

37

# Returns: "/System/Library/Frameworks/AppKit.framework"

38

"""

39

```

40

41

### Dynamic Library Loading

42

43

Functions for loading dynamic libraries and shared objects.

44

45

```python { .api }

46

def dyld_library(path: str):

47

"""

48

Load a dynamic library from the specified path.

49

50

Args:

51

path (str): Full path to the dynamic library file

52

53

Returns:

54

The loaded library object

55

56

Usage:

57

lib = objc.dyld_library("/usr/lib/libsqlite3.dylib")

58

"""

59

```

60

61

### Bundle Resource Access

62

63

Context manager and functions for working with application bundles and their resources.

64

65

```python { .api }

66

def inBundle(bundlePath: str):

67

"""

68

Context manager for loading resources from a bundle.

69

70

Args:

71

bundlePath (str): Path to the application bundle

72

73

Usage:

74

with objc.inBundle("/Applications/MyApp.app"):

75

# Access bundle resources

76

resource = loadBundleResource("config.plist")

77

"""

78

79

def current_bundle():

80

"""

81

Get the current application bundle.

82

83

Returns:

84

The current NSBundle object, or None if not in a bundle context

85

"""

86

```

87

88

### Bridge Support Integration

89

90

Functions for parsing BridgeSupport XML files and initializing framework wrappers.

91

92

```python { .api }

93

def parseBridgeSupport(xmldata: bytes, globals: dict, frameworkName: str):

94

"""

95

Parse BridgeSupport XML data and populate globals.

96

97

Args:

98

xmldata (bytes): XML data from BridgeSupport file

99

globals (dict): Dictionary to populate with framework symbols

100

frameworkName (str): Name of the framework being loaded

101

102

BridgeSupport files contain metadata about C functions, structures,

103

and constants that cannot be automatically discovered by the bridge.

104

"""

105

106

def initFrameworkWrapper(name: str, frameworkPath: str, frameworkIdentifier: str, globals: dict):

107

"""

108

Initialize a framework wrapper with metadata.

109

110

Args:

111

name (str): Framework name

112

frameworkPath (str): Path to framework bundle

113

frameworkIdentifier (str): Bundle identifier

114

globals (dict): Dictionary to populate with framework symbols

115

"""

116

```

117

118

### Bundle Variable and Function Loading

119

120

Functions for loading variables and functions from loaded bundles.

121

122

```python { .api }

123

def loadBundleVariables(bundle, globals: dict, variableInfo: dict):

124

"""

125

Load global variables from a bundle.

126

127

Args:

128

bundle: The loaded bundle object

129

globals (dict): Dictionary to populate with variables

130

variableInfo (dict): Metadata about variables to load

131

"""

132

133

def loadBundleFunctions(bundle, globals: dict, functionInfo: dict):

134

"""

135

Load C functions from a bundle.

136

137

Args:

138

bundle: The loaded bundle object

139

globals (dict): Dictionary to populate with functions

140

functionInfo (dict): Metadata about functions to load

141

"""

142

```

143

144

## Usage Examples

145

146

### Loading a System Framework

147

148

```python

149

import objc

150

151

# Find and load the WebKit framework

152

webkit_path = objc.pathForFramework("WebKit")

153

if webkit_path:

154

webkit_bundle = objc.dyld_framework(webkit_path)

155

156

# Now WebKit classes are available

157

from WebKit import WKWebView, WKWebViewConfiguration

158

159

config = WKWebViewConfiguration.alloc().init()

160

webview = WKWebView.alloc().initWithFrame_configuration_(

161

((0, 0), (800, 600)), config

162

)

163

```

164

165

### Working with Application Bundles

166

167

```python

168

import objc

169

from Foundation import NSBundle, NSURL

170

171

# Get the main application bundle

172

main_bundle = NSBundle.mainBundle()

173

174

# Access bundle resources

175

with objc.inBundle(main_bundle.bundlePath()):

176

# Load a plist file from the bundle

177

plist_path = main_bundle.pathForResource_ofType_("Info", "plist")

178

if plist_path:

179

plist_url = NSURL.fileURLWithPath_(plist_path)

180

# Process the plist file

181

```

182

183

### Loading a Custom Framework

184

185

```python

186

import objc

187

import os

188

189

# Load a custom framework from your application

190

custom_framework_path = os.path.expanduser("~/Library/Frameworks/MyFramework.framework")

191

192

if os.path.exists(custom_framework_path):

193

# Load the framework

194

framework = objc.dyld_framework(custom_framework_path)

195

196

# Initialize wrapper with BridgeSupport if available

197

bridge_support_path = os.path.join(custom_framework_path, "Resources/BridgeSupport/MyFramework.bridgesupport")

198

if os.path.exists(bridge_support_path):

199

with open(bridge_support_path, 'rb') as f:

200

xml_data = f.read()

201

202

# Create globals dictionary for framework symbols

203

framework_globals = {}

204

objc.parseBridgeSupport(xml_data, framework_globals, "MyFramework")

205

206

# Now framework classes and functions are available

207

MyCustomClass = framework_globals.get('MyCustomClass')

208

if MyCustomClass:

209

instance = MyCustomClass.alloc().init()

210

```

211

212

### Loading Dynamic Libraries

213

214

```python

215

import objc

216

217

# Load a system library

218

sqlite_lib = objc.dyld_library("/usr/lib/libsqlite3.dylib")

219

220

# Load a custom library

221

custom_lib_path = "/usr/local/lib/libmycustomlib.dylib"

222

if os.path.exists(custom_lib_path):

223

custom_lib = objc.dyld_library(custom_lib_path)

224

```