forked from metacall/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhost.py.in
More file actions
46 lines (34 loc) · 957 Bytes
/
host.py.in
File metadata and controls
46 lines (34 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
import sys
# Insert Python Port folder first in the system path list
sys.path.insert(0, '@PROJECT_METACALL_PORTS_DIRECTORY@')
from metacall import metacall, metacall_load_from_memory
script = '''#!/usr/bin/env node
'use strict';
const path = require('path');
/* Load MetaCall addon */
const addon = (() => {
try {
/* This forces metacall port to be run always by metacall cli */
return process._linkedBinding('node_loader_port_module');
} catch (e) {
console.error('MetaCall failed to load, probably you are importing this file from NodeJS directly.');
console.error('You should use MetaCall CLI instead. Install it from: https://github.com/metacall/install');
throw e;
}
})();
function b() {
return addon.metacall('c');
}
module.exports = {
b
};
'''
metacall_load_from_memory('node', script)
def a():
result = metacall('b')
print('Result call from b:')
print(result)
return result
def c():
return 3.0