-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add samples ; Start filling README ; Fix a few platform-specific issues
- Loading branch information
Showing
22 changed files
with
315 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,40 @@ | ||
# interpret | ||
|
||
Turn haxe classes into scriptable/interpretable/hot-reloadable code using hscript | ||
|
||
- [x] Class parsing | ||
- [x] Properties with getters and setters | ||
- [x] Static/Instance methods and properties | ||
 | ||
|
||
## Goals | ||
|
||
### Execute standard haxe code as script | ||
|
||
In contrary of regular hscript, **interpret** takes as input a standard Haxe class. This means you can work on your code with the same IDE, code completino, static analysis tools as you would do for compiled haxe code. | ||
|
||
### No need to use haxe compiler to consume scripts | ||
|
||
Scripts are loaded as raw text by the app embedding **interpret**, parsed and transformed to hscript on the fly. This means you don't need haxe compiler to load a new script. | ||
|
||
As a result, while building a project using haxe compiler can become slower as it gets more and more code in it, updating a script with **interpret** should always be fast, no matter how big is your project, because it doesn't need to build the whole project. It just need to process a single file and execute it, that's it. | ||
|
||
### Prefer portability over performance | ||
|
||
As **interpret** is built on top of hscript to execute haxe code, it is not expected to be fast, but it is very portable and should work fine with any haxe target. | ||
|
||
### Provide live-reload capabilities | ||
|
||
It is possible to write haxe classes with live-reloadable methods using **interpret**'s `Interpretable` interface. Simply saving the file will update the code within a second, without restarting the app. | ||
|
||
On targets supporting haxe's **sys** API, live reload can work without having to run any custom server. The app itself will just watch for changes on the file system. | ||
|
||
It is however possible to provide custom watchers as needed for more complexe scenarios. Some ideas: remotely updating a mobile app (ios/android) through websockets, embedding a code editor in the same app that runs it... | ||
|
||
### Try to stay as close as possible to Haxe | ||
|
||
While **interpret** cannot reproduce 100% of haxe features as script, it is trying its best to cover most of it. It allows to expose _native_ haxe classes and abstracts (and soon enums) to interpretable code, so that it's possible to call them from script, and write code that works the same way, both as compiled code (with haxe compiler) and interpretable code (with **interpret**). | ||
|
||
A typical scenario leveraging this aspect is using **interpret** live-reload while iterating on your app code and testing quickly what it does, then bundling the final binary as compiled, and efficient, haxe code: use scripting in dev, but make no compromise regarding performance in production! | ||
|
||
To see what haxe features are supported, you can take a look at the haxe files in [test script directory](/test/script/), which are all tested and compatible with **interpret**. | ||
|
||
**interpret** is still at an early stage of development and can be improved a lot. New features, like handling of enums and pattern matching, will be added in the future. | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-lib hscript:2.3.0 | ||
-main sample.DynamicClassSample | ||
-cp . | ||
-debug | ||
-js main.js | ||
-lib hxnodejs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-lib hscript:2.3.0 | ||
-main sample.DynamicClassSample | ||
-cp . | ||
-debug | ||
--interp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-lib hscript:2.3.0 | ||
-main sample.LiveReloadSample | ||
-cp . | ||
-debug | ||
-D interpretable | ||
-D interpret_watch | ||
-D interpret_mute_import_warnings | ||
-js main.js | ||
-lib hxnodejs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-lib hscript:2.3.0 | ||
-main sample.LiveReloadSample | ||
-cp . | ||
-debug | ||
-D interpretable | ||
-D interpret_watch | ||
-D interpret_mute_import_warnings | ||
--interp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package sample; | ||
|
||
import sys.io.File; | ||
import interpret.Env; | ||
import interpret.DynamicModule; | ||
|
||
/** A sample that loads and instanciate a dynamic class | ||
from file system and call `hello()` method on it. */ | ||
class DynamicClassSample { | ||
|
||
public static function main() { | ||
|
||
#if js | ||
try { | ||
untyped require('source-map-support').install(); | ||
} catch (e:Dynamic) {} | ||
#end | ||
|
||
// Create env | ||
var env = new Env(); | ||
env.addDefaultModules(); | ||
|
||
// Expose some native modules | ||
// sample.native.NativeClass can be imported and used from interpretable code because we exposed it | ||
env.addModule('sample.native.NativeClass', DynamicModule.fromStatic(sample.native.NativeClass)); | ||
// StringTools can be used with `using` in dynamic classes because we exposed it as well | ||
env.addModule('StringTools', DynamicModule.fromStatic(StringTools)); | ||
|
||
// Read HelloWorld.hx as raw text and add it as dynamic module | ||
env.addModule('sample.script.HelloWorld', DynamicModule.fromString(env, 'HelloWorld', File.getContent('sample/script/HelloWorld.hx'))); | ||
|
||
// Link every modules | ||
env.link(); | ||
|
||
// Load `HelloWorld` dynamic class | ||
var helloWorldClass = env.modules.get('sample.script.HelloWorld').dynamicClasses.get('HelloWorld'); | ||
|
||
// Create instance | ||
var helloWorldInstance = helloWorldClass.createInstance(); | ||
|
||
// Call hello() on this dynamic instance | ||
// (this should print `hello Jeremy`) | ||
helloWorldInstance.call('hello', ['Jeremy']); | ||
|
||
// Call hello without providing a name, should pick a random one | ||
helloWorldInstance.call('hello'); | ||
|
||
} //main | ||
|
||
} //DynamicClassSample |
Oops, something went wrong.