https://github.com/no1wudi/binding
https://github.com/no1wudi/binding
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/no1wudi/binding
- Owner: no1wudi
- Created: 2021-03-22T09:09:07.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-22T09:20:48.000Z (about 4 years ago)
- Last Synced: 2025-02-10T01:34:46.059Z (4 months ago)
- Language: Python
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Language Binding Generator
For help:
```
python binding.py -h
```Now only Duktape supported.
## Syntax
### include
```
[include]
system = ["stdio.h", "stdbool.h"]
custom = ["string.h", "demo.h"]
```Generated:
```
#include
#include#include "string.h"
#include "demo.h"
```### Gloabal function
```
[global.function]
# This 'void' means ignore the return value in generated code
print="void printf(const char *)"
```Generated:
```
duk_push_c_function(ctx, js_print, 1);
duk_put_global_string(ctx, "print");
```Usage in JavaScript:
```
print('Hello -- from Bindgen!\n')
```### Global constant
```
[global.const]
MAXJOBS=16
```Generated:
```
duk_push_int(ctx, 16);
duk_put_global_string(ctx, "MAXJOBS");
```Usage in JavaScript:
```
print(MAXJOBS)
```### Module organization
JavaScript/Wasm has the concept of module,
```
[console.function]
log='void printf(const char *)'[console.const]
INFO='Information'
```Generated:
```
duk_push_object(ctx);
idx = duk_get_top_index(ctx);
duk_push_string(ctx, "log");
duk_push_c_function(ctx, js_log, 1);
duk_def_prop(ctx, idx, DUK_DEFPROP_HAVE_VALUE);
duk_push_string(ctx, "sum");
duk_push_c_function(ctx, js_sum, 3);
duk_def_prop(ctx, idx, DUK_DEFPROP_HAVE_VALUE);
duk_push_string(ctx, "INFO");
duk_push_string(ctx, "Information");
duk_def_prop(ctx, idx, DUK_DEFPROP_HAVE_VALUE);
duk_put_global_string(ctx, "console");
```JavaScript:
```
console.log(console.INFO)
```