Olaf,
The Native/Lua bridge is done. Hopefully you’ll get the newest version from David soon. (We had some server problems today and yesterday… so hopefully everything is smoothed out now.)
Our newest WP8 .NET class framework documentation won’t be uploaded to our website at the moment since we’re gearing up for another release. But that said, the zip file David will send you contains a help file documenting the newest APIs. Plus, our Visual Studio integration will show all of our newest classes and their documentation via intellisense which should help you out.
Below is a quick example on how to communicate between C# and Lua. It’ll exercise some of its capabilities, hopefully giving you an idea on how to use it.
Here is an example MainPage.cs C# code that you can use to hook into the Corona runtime environment, listen in to the Corona runtime’s lifecycle via its .NET events, add Lua style event listeners, and dispatch events to Lua (or even to other .NET event handlers) via a Lua like Runtime:dispatchEvent() call. This code receives and dispatches Corona events.
public partial class MainPage : PhoneApplicationPage { /// \<summary\>Construstor. Initializes member variables and the user interface.\</summary\> public MainPage() { // Initialize this page's components that were set up via the UI designer. InitializeComponent(); // Set up Corona to automatically start up when the control's Loaded event has been raised. // Note: By default, Corona will run the "main.lua" file in the "Assets\Corona" directory. // You can change the defaults via the CoronaPanel's AutoLaunchSettings property. fCoronaPanel.AutoLaunchEnabled = true; // Add Corona event handlers. fCoronaPanel.Runtime.Loaded += OnCoronaRuntimeLoaded; fCoronaPanel.Runtime.Terminating += OnCoronaRuntimeTerminating; // Set up the CoronaPanel control to render fullscreen via the DrawingSurfaceBackgroundGrid control. // This significantly improves the framerate and is the only means of achieving 60 FPS. fCoronaPanel.BackgroundRenderingEnabled = true; fDrawingSurfaceBackgroundGrid.SetBackgroundContentProvider(fCoronaPanel.BackgroundContentProvider); fDrawingSurfaceBackgroundGrid.SetBackgroundManipulationHandler(fCoronaPanel.BackgroundManipulationHandler); } /// \<summary\> /// Called when the CoronaRuntimeEnvironment has been loaded/created and just before it executes the "main.lua". /// \</summary\> /// \<param name="sender"\>Reference to the CoronaRuntime object that raised this event.\</param\> /// \<param name="e"\>Provides access to the CoronaRuntimeEnvironment object that was just created/loaded.\</param\> private void OnCoronaRuntimeLoaded(object sender, CoronaLabs.Corona.WinRT.CoronaRuntimeEventArgs e) { // Set up Corona to call OnCustomCoronaEventReceived() when an event named "customEvent" gets dispatched. var eventHandler = new CoronaLabs.Corona.WinRT.CoronaLuaEventHandler(OnCoronaCustomEventReceived); e.CoronaRuntimeEnvironment.AddEventListener("customEvent", eventHandler); // You can also hook into an existing Corona event if you want to. eventHandler = new CoronaLabs.Corona.WinRT.CoronaLuaEventHandler(OnCoronaEnterFrameEventReceived); e.CoronaRuntimeEnvironment.AddEventListener("enterFrame", eventHandler); } /// \<summary\>Called when the CoronaRuntimeEnvironment is about to be destroyed.\</summary\> /// \<param name="sender"\>Reference to the CoronaRuntime object that raised this event.\</param\> /// \<param name="e"\>Provides access to the CoronaRuntimeEnvironment involved in this event.\</param\> private void OnCoronaRuntimeTerminating(object sender, CoronaLabs.Corona.WinRT.CoronaRuntimeEventArgs e) { // This method gets called when backing out of the app or when the CoronaPanel control // has been unloade/removed from the application page. } /// \<summary\>Called when a Corona event named "customEvent" has been dispatched.\</summary\> /// \<param name="sender"\>The Corona runtime environment the event was dispatched from.\</param\> /// \<param name="e"\>Provides the event table's properties/fields.\</param\> private CoronaLabs.Corona.WinRT.ICoronaBoxedData OnCoronaCustomEventReceived( CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender, CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e) { // Fetch the Corona event name. var coronaEventName = e.EventName; // Fetch the custom event's message field. var boxedMessage = e.Properties.Get("message") as CoronaLabs.Corona.WinRT.CoronaBoxedString; if (boxedMessage != null) { string myMessageFromLua = boxedMessage.ToUtf16String(); } // Return a string back to whoever dispatched this event. return CoronaLabs.Corona.WinRT.CoronaBoxedString.From("Hello from C#."); } /// \<summary\> /// \<para\>Called when Corona's "enterFrame" event hsa been dispatched by Corona.\</para\> /// \<para\>This is just an example. Not recommended since this might reduce framerate a bit.\</para\> /// \</summary\> private CoronaLabs.Corona.WinRT.ICoronaBoxedData OnCoronaEnterFrameEventReceived( CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender, CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e) { // Create a custom Corona event named "dotNetEvent" and dispatch it. var eventProperties = CoronaLabs.Corona.WinRT.CoronaLuaEventProperties.CreateWithName("dotNetEvent"); eventProperties.Set("message", "This event came from my C#."); eventProperties.Set("isCool", true); eventProperties.Set("powerLevel", 9000); var result = sender.DispatchEvent(new CoronaLabs.Corona.WinRT.CoronaLuaEventArgs(eventProperties)); var boxedMessage = result.ReturnedValue as CoronaLabs.Corona.WinRT.CoronaBoxedString; if (boxedMessage != null) { var returnedMessage = boxedMessage.ToUtf16String(); } // Corona's "enterFrame" event ignores return values. So, just return null. return null; } }
And here is main.lua code that goes with the above code. It will receive and dispatch events to/from C#.
-- Called when an event named "dotNetEvent" has been dispatched from C#. local function onDotNetEventReceived(event) -- Let's send an event named "customEvent" back to C#. local myNewEvent = { name = "customEvent", message = "This event came from Lua.", } local result = Runtime:dispatchEvent(myNewEvent) print("The 'customEvent' handler returned " .. tostring(result)) -- We can return a value to the dispatcher if we want. return "Hello from Lua!" end Runtime:addEventListener("dotNetEvent", onDotNetEventReceived)
I hope this helps!