https://github.com/charto/emscripten-library-decorator
Decorators for writing Emscripten libraries
https://github.com/charto/emscripten-library-decorator
emscripten
Last synced: 9 months ago
JSON representation
Decorators for writing Emscripten libraries
- Host: GitHub
- URL: https://github.com/charto/emscripten-library-decorator
- Owner: charto
- License: mit
- Created: 2015-08-29T15:43:57.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-04-22T06:26:01.000Z (over 8 years ago)
- Last Synced: 2025-03-21T23:51:14.486Z (10 months ago)
- Topics: emscripten
- Language: TypeScript
- Size: 19.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
emscripten-library-decorator
============================
This package provides decorators for writing Emscripten libraries.
```typescript
function _print(message: string) {
console.log(message);
}
@exportLibrary
class test {
@dep(_print)
static hello() {
_print('Hello, World!!');
}
static foobar = 42;
};
```
The class decorator `@exportLibrary` exports the static members of the class as an Emscripten library. Place it with no arguments just before the class.
The property decorator `@dep` is for listing dependencies. It ensures that when an exported function is used in the C or C++ code, other required functions are also included in the compiled Emscripten output after dead code elimination. Place it just before a function with any number of parameters listing the other required functions.
The dependencies should be global functions and their name should begin with an underscore. Otherwise Emscripten's name mangling will change their name in the output making any calls to them fail.
There is a [longer article](http://blog.charto.net/asm-js/Writing-Emscripten-libraries-in-TypeScript/) with more information.
API
===
Docs generated using [`docts`](https://github.com/charto/docts)
>
>
> ### Function [`defineHidden`](#api-defineHidden)
> @_defineHidden decorator.
> Assign to a local variable called _defineHidden before using.
> Apply to a property to protect it from modifications and hide it.
> Source code: [`<>`](http://github.com/charto/emscripten-library-decorator/blob/74128b8/index.ts#L107-L116)
> > **defineHidden( )** ⇒ (target: Object, key: string) => void [`<>`](http://github.com/charto/emscripten-library-decorator/blob/74128b8/index.ts#L107-L116)
> > ▫ value? any
>
>
> ### Function [`dep`](#api-dep)
> @dep decorator.
> Apply to a function, to list other required variables needing protection
> from dead code removal.
> Arguments can be functions or names of global variables.
> Source code: [`<>`](http://github.com/charto/emscripten-library-decorator/blob/74128b8/index.ts#L20-L48)
> > **dep( )** ⇒ (target: Object, functionName: string) => void [`<>`](http://github.com/charto/emscripten-library-decorator/blob/74128b8/index.ts#L20-L48)
> > ▪ depList ((...args: any[]) => any | string)[]
>
>
> ### Function [`exportLibrary`](#api-exportLibrary)
> @exportLibrary decorator.
> Apply to a class with static methods, to export them as functions.
> Source code: [`<>`](http://github.com/charto/emscripten-library-decorator/blob/74128b8/index.ts#L53-L55)
> > **exportLibrary( )** ⇒ void [`<>`](http://github.com/charto/emscripten-library-decorator/blob/74128b8/index.ts#L53-L55)
> > ▪ target any
>
>
> ### Function [`prepareNamespace`](#api-prepareNamespace)
> @prepareNamespace decorator.
> Apply to an empty, named dummy class defined at the end of the namespace
> block, to prepare its contents for export in an Emscripten library.
> Namespaces with matching names in different files are merged together.
> All code in the block is separated because Emscripten only outputs global
> functions, not methods.
> Source code: [`<>`](http://github.com/charto/emscripten-library-decorator/blob/74128b8/index.ts#L66-L77)
> > **prepareNamespace( )** ⇒ (target: any) => void [`<>`](http://github.com/charto/emscripten-library-decorator/blob/74128b8/index.ts#L66-L77)
> > ▪ name string
>
>
> ### Function [`publishNamespace`](#api-publishNamespace)
> Call once per namespace at the global level, after all files with contents
> in that namespace have been imported. Clears the namespace and exports a
> "postset" function to populate it using its original code.
> Source code: [`<>`](http://github.com/charto/emscripten-library-decorator/blob/74128b8/index.ts#L83-L101)
> > **publishNamespace( )** ⇒ void [`<>`](http://github.com/charto/emscripten-library-decorator/blob/74128b8/index.ts#L83-L101)
> > ▪ name string
>
>
> ### Function [`setEvil`](#api-setEvil)
> Allow decorators to call eval() in the context that called them.
> This is needed for various transformations.
> Source code: [`<>`](http://github.com/charto/emscripten-library-decorator/blob/74128b8/index.ts#L11-L13)
> > **setEvil( )** ⇒ void [`<>`](http://github.com/charto/emscripten-library-decorator/blob/74128b8/index.ts#L11-L13)
> > ▪ otherEval (code: string) => any must be this function: (code: string) => eval(code)
License
-------
[The MIT License](https://raw.githubusercontent.com/charto/emscripten-library-decorator/master/LICENSE)
Copyright (c) 2015-2017 BusFaster Ltd