Browse Source

Merge pull request #1290 from AtomicGameEngine/JME-ATOMIC-1203

[TypeScript] - Add strongly type events (native and script)
JoshEngebretson 9 years ago
parent
commit
1b695e1f90

+ 1 - 1
Script/AtomicEditor/hostExtensions/languageExtensions/CSharpLanguageExtension.ts

@@ -162,7 +162,7 @@ export default class CSharpLanguageExtension implements Editor.HostExtensions.Re
             this.isNETProject = true;
             this.isNETProject = true;
             this.configureNETProjectMenu();
             this.configureNETProjectMenu();
 
 
-            this.eventObject.subscribeToEvent("NETBuildResult", (eventData:ToolCore.NETBuildResult) => {
+            this.eventObject.subscribeToEvent("NETBuildResult", (eventData:ToolCore.NETBuildResultEvent) => {
 
 
                 if (!eventData.success) {
                 if (!eventData.success) {
 
 

+ 2 - 2
Script/AtomicEditor/ui/Shortcuts.ts

@@ -30,9 +30,9 @@ class Shortcuts extends Atomic.ScriptObject {
 
 
         super();
         super();
 
 
-        this.subscribeToEvent("UIShortcut", (ev: Atomic.UIShortcutEvent) => this.handleUIShortcut(ev));
+        this.subscribeToEvent(Atomic.UIShortcutEvent ( (ev) => this.handleUIShortcut(ev)));
 
 
-        this.subscribeToEvent("KeyDown", (ev: Atomic.KeyDownEvent) => this.handleKeyDown(ev));
+        this.subscribeToEvent(Atomic.KeyDownEvent( (ev) => this.handleKeyDown(ev)));
 
 
 
 
     }
     }

+ 1 - 1
Script/AtomicEditor/ui/frames/inspector/InspectorFrame.ts

@@ -90,7 +90,7 @@ class InspectorFrame extends ScriptWidget {
 
 
             for (var i = 0; i < selection.getSelectedNodeCount(); i++) {
             for (var i = 0; i < selection.getSelectedNodeCount(); i++) {
 
 
-                this.handleSceneNodeSelected( { node: selection.getSelectedNode(i),  scene: this.scene, selected: true, quiet: true} );
+                this.handleSceneNodeSelected( <Editor.SceneNodeSelectedEvent> { node: selection.getSelectedNode(i),  scene: this.scene, selected: true, quiet: true} );
 
 
             }
             }
 
 

+ 3 - 1
Script/Packages/Atomic/Core.json

@@ -25,7 +25,9 @@
 		"Object" : [
 		"Object" : [
 			"sendEvent(eventType:string, data?:Object);",
 			"sendEvent(eventType:string, data?:Object);",
 			"subscribeToEvent(eventType:string, callback:(data:any) => void);",
 			"subscribeToEvent(eventType:string, callback:(data:any) => void);",
-			"subscribeToEvent(sender:AObject, eventType:string, callback:(data: any) => void);"
+			"subscribeToEvent(sender:AObject, eventType:string, callback:(data: any) => void);",
+			"subscribeToEvent(eventMetaData:Atomic.EventMetaData);",
+			"subscribeToEvent(sender: AObject, eventMetaData:Atomic.EventMetaData);"
 		]
 		]
 	},
 	},
 	"haxe_decl" : {
 	"haxe_decl" : {

+ 17 - 292
Script/TypeScript/AtomicWork.d.ts

@@ -26,6 +26,23 @@ declare module Atomic {
 
 
     // end subsystems
     // end subsystems
 
 
+    // Base interface for events, contains eventType string and callback
+    interface EventMetaData
+    {
+        _eventType: string;
+        _callback: any;
+    }
+
+    interface NativeEvent extends EventMetaData
+    {
+    }
+
+    interface ScriptEvent extends EventMetaData
+    {
+    }
+
+    // typed callback generic
+    type EventCallback<T extends EventMetaData> = (data: T) => void;
 
 
     export interface PathInfo {
     export interface PathInfo {
 
 
@@ -35,16 +52,6 @@ declare module Atomic {
 
 
     }
     }
 
 
-    export interface ScreenModeEvent {
-
-        width: number;
-        height: number;
-        fullscreen: boolean;
-        resizable: boolean;
-        borderless: boolean;
-
-    }
-
     export interface Ray {
     export interface Ray {
         /** Ray origin */
         /** Ray origin */
         origin: Atomic.Vector3;
         origin: Atomic.Vector3;
@@ -104,162 +111,6 @@ declare module Atomic {
         subObject: number;
         subObject: number;
     }
     }
 
 
-    export interface KeyDownEvent {
-
-        // keycode
-        key: number;
-        //  Atomic.QUAL_SHIFT, Atomic.QUAL_CTRL, Atomic.QUAL_ALT, Atomic.QUAL_ANY
-        qualifiers: number;
-
-        // mouse buttons down
-        buttons: number;
-
-    }
-
-    export interface KeyUpEvent {
-
-        // keycode
-        key: number;
-        //  Atomic.QUAL_SHIFT, Atomic.QUAL_CTRL, Atomic.QUAL_ALT, Atomic.QUAL_ANY
-        qualifiers: number;
-        // mouse buttons down
-        buttons: number;
-
-    }
-
-    export interface UIShortcutEvent {
-
-        // keycode
-        key: number;
-        //  Atomic.QUAL_SHIFT, Atomic.QUAL_CTRL, Atomic.QUAL_ALT, Atomic.QUAL_ANY
-        qualifiers: number;
-
-    }
-
-    export interface UIListViewSelectionChangedEvent {
-
-        refid: string;
-        selected: boolean;
-
-    }
-
-    export interface NodeAddedEvent {
-
-        scene: Atomic.Scene;
-        parent: Atomic.Node;
-        node: Atomic.Node;
-
-    }
-
-    export interface NodeRemovedEvent {
-
-        scene: Atomic.Scene;
-        parent: Atomic.Node;
-        node: Atomic.Node;
-
-    }
-
-    export interface NodeNameChangedEvent {
-
-        scene: Atomic.Scene;
-        node: Atomic.Node;
-
-    }
-
-    export interface UIWidgetEvent {
-
-        handler: UIWidget;
-        target: UIWidget;
-        type: number; /*UIWidgetEventType*/
-        x: number;
-        y: number;
-        deltax: number;
-        deltay: number;
-        count: number;
-        key: number;
-        specialkey: number;
-        modifierkeys: number;
-        refid: string;
-        touch: boolean;
-    }
-
-    export interface UIWidgetFocusChangedEvent {
-        widget: UIWidget;
-        focused: boolean;
-    }
-
-    export interface UIWidgetEditCompleteEvent {
-        widget: UIWidget;
-    }
-
-    export interface UIWidgetDeletedEvent {
-
-        widget: UIWidget;
-    }
-
-    export interface DragBeginEvent {
-
-        source: UIWidget;
-        dragObject: UIDragObject;
-    }
-
-    export interface DragEnterWidgetEvent {
-
-        widget: UIWidget;
-        dragObject: UIDragObject;
-    }
-
-    export interface DragExitWidgetEvent {
-
-        widget: UIWidget;
-        dragObject: UIDragObject;
-    }
-
-    export interface DragEndedEvent {
-
-        target: UIWidget;
-        dragObject: UIDragObject;
-    }
-
-    export interface TemporaryChangedEvent {
-
-        serializable: Atomic.Serializable;
-
-    }
-
-    export interface ComponentAddedEvent {
-
-        scene: Atomic.Scene;
-        node: Atomic.Node;
-        component: Atomic.Component;
-
-    }
-
-    export interface ComponentRemovedEvent {
-
-        scene: Atomic.Scene;
-        node: Atomic.Node;
-        component: Atomic.Component;
-
-    }
-
-    export interface IPCJSErrorEvent {
-
-        errorName: string;
-        errorMessage: string;
-        errorFileName: string;
-        errorLineNumber: number;
-        errorStack: string;
-
-    }
-
-
-    export interface IPCMessageEvent {
-
-        message: string;
-        value: number;
-    }
-
     export interface AttributeInfo {
     export interface AttributeInfo {
 
 
         type: VariantType;
         type: VariantType;
@@ -310,135 +161,9 @@ declare module Atomic {
 
 
 }
 }
 
 
-declare module Editor {
-
-    export interface SceneNodeSelectedEvent {
-        scene: Atomic.Scene;
-        node: Atomic.Node;
-        selected: boolean;
-        quiet: boolean;
-    }
-
-    export interface SceneEditAddRemoveNodesEvent {
-
-        end: boolean;
-
-    }
-
-
-    export interface SceneEditNodeAddedEvent {
-
-        scene: Atomic.Scene;
-        parent: Atomic.Node;
-        node: Atomic.Node;
-
-    }
-
-    export interface SceneEditNodeRemovedEvent {
-
-        scene: Atomic.Scene;
-        parent: Atomic.Node;
-        node: Atomic.Node;
-
-    }
-
-    export interface SceneEditComponentAddedRemovedEvent {
-
-        scene: Atomic.Scene;
-        node: Atomic.Node;
-        component: Atomic.Component;
-        removed: boolean;
-    }
-
-    export interface SceneEditStateChangeEvent {
-
-        serializable: Atomic.Serializable;
-
-    }
-
-    export interface SceneEditNodeCreatedEvent {
-        node: Atomic.Node;
-    }
-
-    export interface GizmoEditModeChangedEvent {
-        mode: EditMode;
-    }
-
-    export interface GizmoAxisModeChangedEvent {
-        mode: AxisMode;
-    }
-
-}
 
 
 declare module ToolCore {
 declare module ToolCore {
 
 
-    export interface ResourceAddedEvent {
-
-        guid: string;
-
-    }
-
-    export interface ResourceRemovedEvent {
-
-        guid: string;
-
-    }
-
-    export interface LicenseDeactivationErrorEvent {
-
-        message: string;
-
-    }
-
-    export interface AssetImportErrorEvent {
-
-        path: string;
-        guid: string;
-        error: string;
-    }
-
-    export interface AssetRenamedEvent {
-
-        asset: Asset;
-
-    }
-
-    export interface AssetMovedEvent {
-
-        asset: Asset;
-        oldPath: string;
-
-    }
-
-
-    export interface PlatformChangedEvent {
-
-        platform: ToolCore.Platform;
-
-    }
-
-    export interface BuildOutputEvent {
-
-        text: string;
-
-    }
-
-    export interface BuildCompleteEvent {
-
-        platformID: number;
-        message: string;
-        success: boolean;
-        buildFolder: string;
-
-    }
-
-    export interface NETBuildResult {
-
-        success: boolean;
-        build: NETBuild;
-        errorText: string;
-    }
-
     export var toolEnvironment: ToolEnvironment;
     export var toolEnvironment: ToolEnvironment;
     export var toolSystem: ToolSystem;
     export var toolSystem: ToolSystem;
     export var assetDatabase: AssetDatabase;
     export var assetDatabase: AssetDatabase;

+ 30 - 0
Source/AtomicJS/Javascript/JSAPI.cpp

@@ -197,6 +197,36 @@ void js_setup_prototype(JSVM* vm, const char* package, const char* classname, co
     assert (top == duk_get_top(ctx));
     assert (top == duk_get_top(ctx));
 }
 }
 
 
+
+// When subscribing to native event, this method will be called
+// to provide the event meta data (type and callback)
+static int js_push_native_event_metadata(duk_context* ctx) {
+
+    duk_push_current_function(ctx);
+
+    duk_push_object(ctx);
+    duk_get_prop_string(ctx, -2, "_eventType");
+    duk_put_prop_string(ctx, -2, "_eventType");
+    duk_dup(ctx, 0);
+    duk_put_prop_string(ctx, -2, "_callback");
+
+    return 1;
+}
+
+void js_define_native_event(duk_context* ctx, const String& eventType, const String &eventName)
+{
+    // push c function which takes 1 argument, the callback
+    duk_push_c_function(ctx, js_push_native_event_metadata, 1);
+
+    // store the event type in the function object
+    duk_push_string(ctx, eventType.CString());
+    duk_put_prop_string(ctx, -2, "_eventType");
+
+    // store to module object
+    duk_put_prop_string(ctx, -2, eventName.CString());
+
+}
+
 void js_object_to_variantmap(duk_context* ctx, int objIdx, VariantMap &v)
 void js_object_to_variantmap(duk_context* ctx, int objIdx, VariantMap &v)
 {
 {
     v.Clear();
     v.Clear();

+ 3 - 0
Source/AtomicJS/Javascript/JSAPI.h

@@ -54,6 +54,9 @@ void js_class_push_propertyobject(JSVM* vm, const char* package, const char* cla
 void js_class_get_prototype(duk_context* ctx, const char* package, const char *classname);
 void js_class_get_prototype(duk_context* ctx, const char* package, const char *classname);
 void js_class_get_constructor(duk_context* ctx, const char* package, const char *classname);
 void js_class_get_constructor(duk_context* ctx, const char* package, const char *classname);
 
 
+// setup a native event wrapper on module object at the top of the stack
+void js_define_native_event(duk_context* ctx, const String& eventType, const String& eventName);
+
 /// Pushes variant value or undefined if can't be pushed
 /// Pushes variant value or undefined if can't be pushed
 void js_push_variant(duk_context* ctx, const Variant &v);
 void js_push_variant(duk_context* ctx, const Variant &v);
 void js_push_variantmap(duk_context* ctx, const VariantMap &vmap);
 void js_push_variantmap(duk_context* ctx, const VariantMap &vmap);

+ 52 - 1
Source/AtomicJS/Javascript/JSCore.cpp

@@ -31,18 +31,63 @@ namespace Atomic
 
 
 static int Object_SubscribeToEvent(duk_context* ctx)
 static int Object_SubscribeToEvent(duk_context* ctx)
 {
 {
-
     int top = duk_get_top(ctx);
     int top = duk_get_top(ctx);
 
 
     Object* sender = NULL;
     Object* sender = NULL;
 
 
     StringHash eventType = StringHash::ZERO;
     StringHash eventType = StringHash::ZERO;
 
 
+    // if we have a single argument, it is event meta data
+    if (top == 1)
+    {
+        if (duk_is_object(ctx, 0))
+        {
+            duk_get_prop_string(ctx, 0, "_callback");
+            duk_get_prop_string(ctx, 0, "_eventType");
+
+            if (duk_is_string(ctx, -1) && duk_is_function(ctx, -2))
+            {
+                duk_replace(ctx, 0);
+
+                top = duk_get_top(ctx);
+            }
+        }
+
+        if (top != 2)
+        {
+            duk_push_string(ctx, "Object.subscribeToEvent() - Bad meta data");
+            duk_throw(ctx);
+        }
+    }
+
+
+    // unwrap event data
+    if ( top == 2 && duk_is_object(ctx, 0) && duk_is_object(ctx, 1))
+    {
+        duk_get_prop_string(ctx, 1, "_callback");
+        duk_get_prop_string(ctx, 1, "_eventType");
+
+        if (duk_is_string(ctx, -1) && duk_is_function(ctx, -2))
+        {
+            duk_replace(ctx, 1);
+
+            top = duk_get_top(ctx);
+        }
+
+        if (top != 3)
+        {
+            duk_push_string(ctx, "Object.subscribeToEvent() - Bad sender meta data");
+            duk_throw(ctx);
+        }
+    }
+
     if ( top == 2 ) // General notification: subscribeToEvent("ScreenMode", function() {});
     if ( top == 2 ) // General notification: subscribeToEvent("ScreenMode", function() {});
     {
     {
         if (duk_is_string(ctx, 0) && duk_is_function(ctx, 1))
         if (duk_is_string(ctx, 0) && duk_is_function(ctx, 1))
         {
         {
             eventType = duk_to_string(ctx, 0);
             eventType = duk_to_string(ctx, 0);
+        } else if(duk_is_number(ctx, 0) && duk_is_function(ctx, 1)) {
+            eventType = StringHash(duk_to_number(ctx, 0));
         }
         }
     }
     }
     else if (top == 3) // Listen to specific object sender subscribeToEvent(graphics, "ScreenMode", function() {});
     else if (top == 3) // Listen to specific object sender subscribeToEvent(graphics, "ScreenMode", function() {});
@@ -52,6 +97,10 @@ static int Object_SubscribeToEvent(duk_context* ctx)
             sender = js_to_class_instance<Object>(ctx, 0, 0);
             sender = js_to_class_instance<Object>(ctx, 0, 0);
             eventType = duk_to_string(ctx, 1);
             eventType = duk_to_string(ctx, 1);
         }
         }
+        else if (duk_is_object(ctx, 0) && duk_is_number(ctx, 1) && duk_is_function(ctx, 2)) {
+            sender = js_to_class_instance<Object>(ctx, 0, 0);
+            eventType = StringHash(duk_to_number(ctx, 1));
+        }
     }
     }
 
 
     if ( eventType == StringHash::ZERO)
     if ( eventType == StringHash::ZERO)
@@ -90,7 +139,9 @@ static int Object_SubscribeToEvent(duk_context* ctx)
 
 
     duk_get_prop_string(ctx, -1, "__eventHelperFunctions");
     duk_get_prop_string(ctx, -1, "__eventHelperFunctions");
     assert(duk_is_object(ctx, -1));
     assert(duk_is_object(ctx, -1));
+
     assert(duk_is_function(ctx, sender ? 2 : 1));
     assert(duk_is_function(ctx, sender ? 2 : 1));
+
     duk_dup(ctx, sender ? 2 : 1);
     duk_dup(ctx, sender ? 2 : 1);
     duk_put_prop_string(ctx, -2,  eventType.ToString().CString());
     duk_put_prop_string(ctx, -2,  eventType.ToString().CString());
     duk_pop(ctx);
     duk_pop(ctx);

+ 20 - 1
Source/ToolCore/JSBind/JSBEvent.cpp

@@ -54,8 +54,22 @@ JSBPackage* JSBEvent::GetPackage()
     return module_->GetPackage();
     return module_->GetPackage();
 }
 }
 
 
-String JSBEvent::GetScriptEventName() const
+String JSBEvent::GetScriptEventName(BindingLanguage language) const
 {
 {
+
+    if (language == BINDINGLANGUAGE_JAVASCRIPT) {
+
+        if (eventName_ == "WidgetEvent")
+        {
+            return "UIWidgetEvent";
+        }
+
+        if (eventName_ == "WidgetDeleted")
+        {
+            return "UIWidgetDeletedEvent";
+        }
+    }
+
     if (eventName_.EndsWith("Event"))
     if (eventName_.EndsWith("Event"))
         return eventName_;
         return eventName_;
 
 
@@ -63,6 +77,11 @@ String JSBEvent::GetScriptEventName() const
 
 
 }
 }
 
 
+unsigned JSBEvent::GetEventHash() const
+{
+    return StringHash(eventName_).Value();
+}
+
 bool JSBEvent::ScanModuleEvents(JSBModule* module)
 bool JSBEvent::ScanModuleEvents(JSBModule* module)
 {
 {
     const Vector<SharedPtr<JSBHeader>>& headers = module->GetHeaders();
     const Vector<SharedPtr<JSBHeader>>& headers = module->GetHeaders();

+ 4 - 1
Source/ToolCore/JSBind/JSBEvent.h

@@ -24,6 +24,8 @@
 
 
 #include <Atomic/Core/Object.h>
 #include <Atomic/Core/Object.h>
 
 
+#include "JSBindTypes.h"
+
 using namespace Atomic;
 using namespace Atomic;
 
 
 namespace ToolCore
 namespace ToolCore
@@ -54,8 +56,9 @@ namespace ToolCore
 
 
         const String& GetEventID() const { return eventID_; }
         const String& GetEventID() const { return eventID_; }
         const String& GetEventName() const { return eventName_; }
         const String& GetEventName() const { return eventName_; }
+        unsigned GetEventHash() const;
         /// Generally this is the EventName + "Event"
         /// Generally this is the EventName + "Event"
-        String GetScriptEventName() const;
+        String GetScriptEventName(BindingLanguage language = BINDINGLANGUAGE_ANY) const;
         const Vector<EventParam>& GetParameters() const { return parameters_;  }
         const Vector<EventParam>& GetParameters() const { return parameters_;  }
 
 
 
 

+ 94 - 0
Source/ToolCore/JSBind/JSBTypeScript.cpp

@@ -30,6 +30,7 @@
 #include "JSBModule.h"
 #include "JSBModule.h"
 #include "JSBFunction.h"
 #include "JSBFunction.h"
 #include "JSBTypeScript.h"
 #include "JSBTypeScript.h"
+#include "JSBEvent.h"
 
 
 namespace ToolCore
 namespace ToolCore
 {
 {
@@ -362,6 +363,98 @@ void JSBTypeScript::ExportModuleEnums(JSBModule* module)
 
 
 }
 }
 
 
+
+void JSBTypeScript::ExportModuleEvents(JSBModule* module)
+{
+
+    String source;
+
+    const Vector<SharedPtr<JSBEvent>>& events = module->GetEvents();
+
+    for (unsigned i = 0; i < events.Size(); i++)
+    {
+        JSBEvent* event = events[i];
+        String scriptEventName = event->GetScriptEventName(BINDINGLANGUAGE_JAVASCRIPT);
+
+        source += ToString("    export interface %s extends Atomic.NativeEvent {\n", scriptEventName.CString());
+
+        // parameters
+
+        const Vector<JSBEvent::EventParam>& params = event->GetParameters();
+
+        for (unsigned j = 0; j < params.Size(); j++)
+        {
+            const JSBEvent::EventParam& p = params[j];
+
+            JSBClass* cls = JSBPackage::GetClassAllPackages(p.typeInfo_);
+
+            String typeName = p.typeInfo_;
+            String enumTypeName = p.enumTypeName_;
+
+            String paramName = p.paramName_;
+
+            //TODO: Is there a standard naming module that could handle this?
+            if (paramName == "GUID")
+                paramName = "guid";
+            else if (paramName == "RefID")
+                paramName = "refid"; // do nothing
+            else
+                paramName[0] = tolower(paramName[0]);
+
+            if (!cls)
+                typeName = typeName.ToLower();
+            else
+                typeName = cls->GetName();
+
+            if (typeName == "int" || typeName == "float" || typeName == "unsigned" ||
+                typeName == "bool" || typeName == "string" || typeName == "enum" || cls)
+            {
+
+                bool isEnum = false;
+                if (typeName == "enum")
+                {
+                    isEnum = true;
+                    // Once proper TypeScript enums are in place, uncomment the following.  See: #1268
+                    //if (enumTypeName.Length())
+                    //    typeName = enumTypeName;
+                    //else
+                    typeName = "number";
+                }
+
+                if (typeName == "int" || typeName == "float" || typeName == "unsigned")
+                {
+                    typeName = "number";
+                } else if (typeName == "bool") {
+                    typeName = "boolean";
+                } else if (cls) {
+                    typeName = ToString("%s.%s", cls->GetPackage()->GetName().CString(), typeName.CString());
+                }
+
+                if (isEnum && enumTypeName.Length())
+                {
+                    source += ToString("        /** Enum: %s */\n", enumTypeName.CString());
+                    source += ToString("        %s : %s;\n", paramName.CString(), typeName.CString());
+                } else {
+                    source += ToString("        %s : %s;\n", paramName.CString(), typeName.CString());
+                }
+            }
+            else
+            {
+                source += ToString("        // Unmapped Native Type:%s \n", typeName.CString());
+                source += ToString("        // %s : any;\n", p.paramName_.ToLower().CString());
+            }
+        }
+
+        source += "    }\n\n";
+
+        // Write the event function signature
+
+        source += ToString("\nexport function %s (callback : Atomic.EventCallback<%s>) : Atomic.EventMetaData;\n\n", scriptEventName.CString(), scriptEventName.CString());
+
+    }
+    source_ += source;
+}
+
 void JSBTypeScript::WriteToFile(const String &path)
 void JSBTypeScript::WriteToFile(const String &path)
 {
 {
     File file(package_->GetContext());
     File file(package_->GetContext());
@@ -405,6 +498,7 @@ void JSBTypeScript::Emit(JSBPackage* package, const String& path)
         source_ += "// MODULE: " + modules[i]->GetName() + "\n";
         source_ += "// MODULE: " + modules[i]->GetName() + "\n";
         source_ += "//----------------------------------------------------\n\n";
         source_ += "//----------------------------------------------------\n\n";
         ExportModuleClasses(modules[i]);
         ExportModuleClasses(modules[i]);
+        ExportModuleEvents(modules[i]);
     }
     }
 
 
 
 

+ 2 - 0
Source/ToolCore/JSBind/JSBTypeScript.h

@@ -58,6 +58,8 @@ private:
     void ExportModuleConstants(JSBModule*  moduleName);
     void ExportModuleConstants(JSBModule*  moduleName);
     void ExportModuleClasses(JSBModule*  moduleName);
     void ExportModuleClasses(JSBModule*  moduleName);
 
 
+    void ExportModuleEvents(JSBModule* module);
+
     void WriteToFile(const String& path);
     void WriteToFile(const String& path);
 
 
     JSBPackage* package_;
     JSBPackage* package_;

+ 11 - 1
Source/ToolCore/JSBind/JavaScript/JSModuleWriter.cpp

@@ -29,7 +29,7 @@
 #include "../JSBEnum.h"
 #include "../JSBEnum.h"
 #include "../JSBClass.h"
 #include "../JSBClass.h"
 #include "../JSBFunction.h"
 #include "../JSBFunction.h"
-
+#include "../JSBEvent.h"
 
 
 #include "JSModuleWriter.h"
 #include "JSModuleWriter.h"
 #include "JSClassWriter.h"
 #include "JSClassWriter.h"
@@ -238,6 +238,7 @@ void JSModuleWriter::WriteModulePreInit(String& source)
             itr++;
             itr++;
         }
         }
     }
     }
+
     source += "// constants\n";
     source += "// constants\n";
 
 
     Vector<String> constants = module_->constants_.Keys();
     Vector<String> constants = module_->constants_.Keys();
@@ -252,6 +253,15 @@ void JSModuleWriter::WriteModulePreInit(String& source)
         source.AppendWithFormat("duk_put_prop_string(ctx, -2, \"%s\");\n", constants.At(i).CString());
         source.AppendWithFormat("duk_put_prop_string(ctx, -2, \"%s\");\n", constants.At(i).CString());
     }
     }
 
 
+    source += "// events\n";
+
+    const Vector<SharedPtr<JSBEvent>>& events = module_->GetEvents();
+
+    for (unsigned i = 0; i < events.Size(); i++)
+    {
+        source.AppendWithFormat("js_define_native_event(ctx, \"%s\", \"%s\");\n", events[i]->GetEventName().CString(), events[i]->GetScriptEventName(BINDINGLANGUAGE_JAVASCRIPT).CString());
+    }
+
     source += "duk_pop(ctx);\n";
     source += "duk_pop(ctx);\n";
     source += "// end enums and constants\n";
     source += "// end enums and constants\n";
 
 

+ 4 - 4
Source/ToolCore/NETTools/NETBuildSystem.h

@@ -35,14 +35,14 @@ namespace ToolCore
 
 
     ATOMIC_EVENT(E_NETBUILDRESULT, NETBuildResult)
     ATOMIC_EVENT(E_NETBUILDRESULT, NETBuildResult)
     {
     {
-        ATOMIC_PARAM(P_BUILD, Build); // NETBuild*
-        ATOMIC_PARAM(P_SUCCESS, Success); // bool = success = true;
-        ATOMIC_PARAM(P_ERRORTEXT, ErrorText); // for failure, the compilation output
+        ATOMIC_PARAM(P_BUILD, Build); // NETBuild
+        ATOMIC_PARAM(P_SUCCESS, Success); // bool success = true;
+        ATOMIC_PARAM(P_ERRORTEXT, ErrorText); // String for failure, the compilation output
     }
     }
 
 
     ATOMIC_EVENT(E_NETBUILDATOMICPROJECT, NETBuildAtomicProject)
     ATOMIC_EVENT(E_NETBUILDATOMICPROJECT, NETBuildAtomicProject)
     {
     {
-        ATOMIC_PARAM(P_PROJECT, Project); // Project*
+        ATOMIC_PARAM(P_PROJECT, Project); // Project
     }
     }
 
 
     enum NETBuildStatus
     enum NETBuildStatus