Flathead = UE4 + Javascript
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Resources
Scripts
Source/Flathead
ThirdParty/v8/Includes
.gitignore
Changelog.md Updating the changelog. Sep 16, 2014
Flathead.uplugin Plugin should be enabled by default Sep 25, 2014
LICENSE Adding basic plugin files. May 26, 2014
Package.bat
Readme.md

Readme.md

Basic Installation & Configuration

  1. Clone the project into your Plugins directory.

  2. Download ThirdParty.zip and unzip it into the Plugins directory.

  3. Add this Flathead to the PrivateDependencyModuleNames list.

    PrivateDependencyModuleNames.Add("Flathead");
  4. Overwrite the base module, hooking into the StartupModule method.

    class FMyJSSampleModule : public FDefaultGameModuleImpl
    {
    	virtual void StartupModule() OVERRIDE;
    };
    
    void FMyJSSampleModule::StartupModule()
    {
    	if (IFlathead::IsAvailable())
    	{
    		IFlathead::Get().LoadGameScript("GameInit.js");
    	}
    }
  5. Add your script file to the /Scripts directory of your project.

    game.log("Game Initialization");
    
    Object.addEventListener("game.tick", function (ev) {
    	game.log("tick.", ev.deltaTime);
    });
  6. Expose your types to JS

    void AFH_FlyingPawn::Expose()
    {
    	if (!IFlathead::IsAvailable())
    		return;
    
    	IFlathead &ref = IFlathead::Get();
    	HandleScope handle_scope(ref.GetIsolate());
    
    	Local<Context> context = ref.GetGlobalContext();
    	Context::Scope ContextScope(context);
    
    	Local<Object> Bob = ref.Expose(this, TEXT("Bob"));
    
    	Bob->Set(String::NewFromUtf8(ref.GetIsolate(), "value", String::kInternalizedString), Number::New(ref.GetIsolate(), 42));
    
    	Local<String> key = String::NewFromUtf8(ref.GetIsolate(), "test", String::kInternalizedString);
    
    	ref.LoadGameScript("BobTest.js");
     }
  7. Enjoy!

Please consult the Wiki for further documentation. If you run into any issues, please file a ticket in the GH Tracker.

Sample Projects & Code

Known Issues

Exposing Functions is currently not working, but may be addressed with updating to a later build of V8. You can contribute to the discussion on this topic here: https://groups.google.com/forum/#!topic/v8-users/cYkuljdJEJ8

Contact

If you have any Questions, Comments, Bug reports or feature requests for this plugin, or you wish to contact me you can and should email me - bob@gneu.org

Alternatively, you can join me in #gneu on irc.freenode.net or irc.gamesurge.net