Skip to content

Commit 7e3f55f

Browse files
committed
ctx.load_script -> ctx.load
1 parent bb7aed7 commit 7e3f55f

9 files changed

+153
-139
lines changed

README.md

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
# quickjs-cffi
22

3-
Python QuickJS CFFI
3+
<!--
4+
[![Build][build-image]]()
5+
[![Status][status-image]][pypi-project-url]
6+
[![Stable Version][stable-ver-image]][pypi-project-url]
7+
[![Coverage][coverage-image]]()
8+
[![Python][python-ver-image]][pypi-project-url]
9+
[![License][mit-image]][mit-url]
10+
-->
11+
[![PyPI](https://img.shields.io/pypi/v/quickjs-cffi)](https://pypi.org/project/quickjs-cffi/)
12+
[![Supported Versions](https://img.shields.io/pypi/pyversions/quickjs-cffi)](https://pypi.org/project/quickjs-cffi)
13+
[![PyPI Downloads](https://img.shields.io/pypi/dm/quickjs-cffi)](https://pypistats.org/packages/quickjs-cffi)
14+
[![Github Downloads](https://img.shields.io/github/downloads/tangledgroup/quickjs-cffi/total.svg?label=Github%20Downloads)]()
15+
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
16+
17+
**Python** binding for [QuickJS Javascript Engine](https://bellard.org/quickjs/) using **cffi**. Supports **x86_64** and **aarch64** platforms.
18+
19+
NOTE: Currently supported operating system is Linux (`manylinux_2_28` and `musllinux_1_2`)
420

521
## Build
622

723
```bash
824
python -m venv venv
925
source venv/bin/activate
1026
pip install poetry
11-
poetry install
12-
pip install tqdm
27+
poetry install --all-extras
1328
```
1429

1530
## Demos

examples/demo_4.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def demo4():
99
ctx: JSContext = rt.new_context()
1010

1111
script_url = 'https://raw.githubusercontent.com/lodash/lodash/refs/heads/main/dist/lodash.min.js'
12-
ctx.load_script(script_url)
12+
ctx.load(script_url)
1313

1414
lodash = ctx['_']
1515
print(lodash, type(lodash))

examples/demo_handlebars.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ def demo_online():
88
rt = JSRuntime()
99
ctx: JSContext = rt.new_context()
1010

11-
script_url = 'https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.8/handlebars.min.js'
12-
ctx.load_script(script_url)
11+
ctx.load('https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.8/handlebars.min.js')
1312

1413
Handlebars = ctx['Handlebars']
1514

@@ -38,8 +37,7 @@ def demo_offline():
3837
rt = JSRuntime()
3938
ctx: JSContext = rt.new_context()
4039

41-
script_url = 'node_modules/handlebars/dist/handlebars.min.js'
42-
ctx.load_script(script_url)
40+
ctx.load('node_modules/handlebars/dist/handlebars.min.js')
4341

4442
Handlebars = ctx['Handlebars']
4543

examples/demo_lodash.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def demo_online():
88
rt = JSRuntime()
99
ctx: JSContext = rt.new_context()
1010

11-
ctx.load_script('https://raw.githubusercontent.com/lodash/lodash/refs/heads/main/dist/lodash.min.js')
11+
ctx.load('https://raw.githubusercontent.com/lodash/lodash/refs/heads/main/dist/lodash.min.js')
1212

1313
lodash = ctx['_']
1414
print(lodash)
@@ -19,7 +19,7 @@ def demo_offline():
1919
rt = JSRuntime()
2020
ctx: JSContext = rt.new_context()
2121

22-
ctx.load_script('node_modules/lodash/lodash.min.js')
22+
ctx.load('node_modules/lodash/lodash.min.js')
2323

2424
lodash = ctx['_']
2525
print(lodash)

examples/demo_yjs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def demo0():
88
rt = JSRuntime()
99
ctx: JSContext = rt.new_context()
1010

11-
ctx.load_script('examples/yjs.js')
11+
ctx.load('examples/yjs.js')
1212

1313
Y = ctx['Y']
1414
# print(Y)
@@ -28,7 +28,7 @@ def demo1():
2828
rt = JSRuntime()
2929
ctx: JSContext = rt.new_context()
3030

31-
ctx.load_script('examples/yjs.js')
31+
ctx.load('examples/yjs.js')
3232

3333
Y = ctx['Y']
3434
# print(Y)
@@ -50,7 +50,7 @@ def demo2():
5050
rt = JSRuntime()
5151
ctx: JSContext = rt.new_context()
5252

53-
ctx.load_script('examples/yjs.js')
53+
ctx.load('examples/yjs.js')
5454

5555
Y = ctx['Y']
5656
# print(Y)

poetry.lock

+116-115
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "quickjs-cffi"
33
version = "0.1.0"
4-
description = "Python binding for quickjs using cffi"
4+
description = "Python binding for QuickJS using CFFI"
55
homepage = "https://github.com/tangledgroup/quickjs-cffi"
66
repository = "https://github.com/tangledgroup/quickjs-cffi"
77
authors = ["Marko Tasic <[email protected]>", "Tangled Group, Inc <[email protected]>"]

quickjs/quickjs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,11 @@ def eval(self, buf: str, filename: str='<inupt>', eval_flags: JSEval | int=JSEva
605605
return val
606606

607607

608-
def load_script(self, path_or_url: str) -> Any:
608+
def load(self, path_or_url: str, eval_flags: JSEval | int=JSEval.TYPE_GLOBAL) -> Any:
609609
path: str
610610
data: str
611611
path, data = read_script(path_or_url)
612-
val: Any = self.eval(data, path)
612+
val: Any = self.eval(data, path, eval_flags)
613613
return val
614614

615615

scripts/build.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,16 @@ def build_quickjs_repo(*args, **kwargs):
234234
_source = '\n'.join(_quickjs_source)
235235
_inline_static_source = '\n'.join(_inline_static_source)
236236

237-
print('='* 80)
238-
print(_inline_static_source)
239-
print('='* 80)
237+
# print('='* 80)
238+
# print(_inline_static_source)
239+
# print('='* 80)
240240

241241
# function declarations for inlined definitions
242242
func_declarations: list[str] | str = get_func_declarations(_inline_static_source)
243243
func_declarations = '\n'.join(func_declarations)
244-
print('-'* 80)
245-
print(func_declarations)
246-
print('-'* 80)
244+
# print('-'* 80)
245+
# print(func_declarations)
246+
# print('-'* 80)
247247
_source += '\n\n' + func_declarations
248248

249249
# extra source declarations
@@ -270,8 +270,8 @@ def build_quickjs_repo(*args, **kwargs):
270270
'''
271271

272272
# print code
273-
for i, line in enumerate(_source.splitlines()):
274-
print(i + 1, ':', line)
273+
# for i, line in enumerate(_source.splitlines()):
274+
# print(i + 1, ':', line)
275275

276276
# build
277277
ffibuilder.cdef(_source)

0 commit comments

Comments
 (0)