Creating plugins for desktop apps

Hi There,

Any chance that corona sdk allows for developers to create plugins for desktop apps - both OSX and win32?

If such an option is already available, is there a tutorial? I couldn’t find one.

Thanks

@ j_wbrown Assuming you don’t just mean Lua stuff, there’s a good set of first steps here for Win32: getting started

If there’s something similar for OSX I’d like to know myself.  :smiley: (Just dipping my feet in the water here…)

Thanks for the comments.

Yeah - I specifically meant for OSX. Was just wondering if there are any tutorials for it.

I was planning to write some obj c / swift for an OSX app.

You can build plugins now for either OS X or Win32 desktop builds. Let me clarify this:

On OS X, you can use pure Lua plugins and you can use Xcode to build native/C/C++/Objective C plugins to be hosted on the plugin store.

On Windows, you can do pure Lua plugins. I believe we are working on making Enterprise work for Windows which will let you do native based plugins. And you can use Visual Studio today along with our Windows Phone 8 platform to make plugins for WP8.

Where you are going to run into problems is if you want to say make a PayPal plugin for instance, you’re going to find that the vendors produce Android and iOS SDK’s, but on the desktop they expect you to use their REST APIs. There is a serious lack of SDK’s for desktop.

Rob

Thanks for responding - rob. It is good that it is already possible to create native plugins for osx via xcode, the thing is that I cannot find a tutorial that showcases how to that for the osx desktop. Could you provide it?

We don’t have a tutorial for that unfortunately. I know we are in the process of working on our Enterprise documentation. I don’t know if this will be included but I can ask that they consider it.

Rob

I heard back from engineering. You can use both Windows and OS X to build plugins as long as you’re using C/C++. There are basically two steps. Lets assume you’re building a plugin called “magic”.

  1. Write your plugin as you would for the Lua C library.

  2. Drop the plugin into a folder that the simulator looks for.

  • For windows you would put: plugin_magic.dll in %APPDATA%\Corona Labs\Corona Simulator\Plugins
  • For OS X you would put: plugin_magic.dylib in ~/Library/Application Support/Corona/Simulator/Plugins/

In your Corona SDK app, you would:

local magic = require( "plugin.magic" ) print( magic.doSomething() )

If you are using Corona Enterprise, a super simplistic code might look like:

#include "CoronaLua.h" #include "CoronaMacros.h" int doSomething(lua\_State \*L) { lua\_pushnumber(L, 42); return 1; } CORONA\_EXPORT int luaopen\_plugin\_magic(lua\_State \*L) { static const luaL\_Reg kVTable[] = { { "doSomething", doSomething }, { NULL, NULL } }; luaL\_openlib( L, "plugin.magic", kVTable, 0 ); return 1; }

If you don’t have Corona Enterprise, you can just build Lua libraries with lua.h and luauxlib.h. Here what that code would look like:

#include "lua.h" #include "lauxlib.h" int doSomething(lua\_State \*L) { lua\_pushnumber(L, 42); return 1; } #if \_\_cplusplus #define EXTERN extern "C" #else #define EXTERN extern #endif #if ( defined( \_WIN32 ) || defined( \_WIN64 ) ) #define CORONA\_DECORATOR EXTERN \_\_declspec( dllexport ) #else #define CORONA\_DECORATOR EXTERN \_\_attribute\_\_((visibility("default"))) #endif CORONA\_DECORATOR int luaopen\_plugin\_magic(lua\_State \*L) { static const luaL\_Reg kVTable[] = { { "doSomething", doSomething }, { NULL, NULL } }; luaL\_openlib( L, "plugin.magic", kVTable, 0 ); return 1; }

Now these are very specific examples and you would have to have a C/C++ interface to the SDK. And of course the thing your are building has to be available for the platform. For instance Facebook does not have a Windows or OS X SDK. They only have Android and iOS.

We assume our Enterprise developers have a working knowledge of Xcode and Visual Studio with regards to how to setup projects, link in 3rd party libraries, etc. We don’t have anything at the moment that would help someone not familiar with these environments to get them going. I believe one of our engineers is going to try and create some templates for this to help getting people less familiar with the environment going. No ETA because he has to work that in to his already deep task list.

Rob

There is additional discussion on building Windows plugins here:

https://forums.coronalabs.com/topic/57623-support-for-nativenewtextfield/?p=298499

Rob

@ j_wbrown Assuming you don’t just mean Lua stuff, there’s a good set of first steps here for Win32: getting started

If there’s something similar for OSX I’d like to know myself.  :smiley: (Just dipping my feet in the water here…)

Thanks for the comments.

Yeah - I specifically meant for OSX. Was just wondering if there are any tutorials for it.

I was planning to write some obj c / swift for an OSX app.

You can build plugins now for either OS X or Win32 desktop builds. Let me clarify this:

On OS X, you can use pure Lua plugins and you can use Xcode to build native/C/C++/Objective C plugins to be hosted on the plugin store.

On Windows, you can do pure Lua plugins. I believe we are working on making Enterprise work for Windows which will let you do native based plugins. And you can use Visual Studio today along with our Windows Phone 8 platform to make plugins for WP8.

Where you are going to run into problems is if you want to say make a PayPal plugin for instance, you’re going to find that the vendors produce Android and iOS SDK’s, but on the desktop they expect you to use their REST APIs. There is a serious lack of SDK’s for desktop.

Rob

Thanks for responding - rob. It is good that it is already possible to create native plugins for osx via xcode, the thing is that I cannot find a tutorial that showcases how to that for the osx desktop. Could you provide it?

We don’t have a tutorial for that unfortunately. I know we are in the process of working on our Enterprise documentation. I don’t know if this will be included but I can ask that they consider it.

Rob

I heard back from engineering. You can use both Windows and OS X to build plugins as long as you’re using C/C++. There are basically two steps. Lets assume you’re building a plugin called “magic”.

  1. Write your plugin as you would for the Lua C library.

  2. Drop the plugin into a folder that the simulator looks for.

  • For windows you would put: plugin_magic.dll in %APPDATA%\Corona Labs\Corona Simulator\Plugins
  • For OS X you would put: plugin_magic.dylib in ~/Library/Application Support/Corona/Simulator/Plugins/

In your Corona SDK app, you would:

local magic = require( "plugin.magic" ) print( magic.doSomething() )

If you are using Corona Enterprise, a super simplistic code might look like:

#include "CoronaLua.h" #include "CoronaMacros.h" int doSomething(lua\_State \*L) { lua\_pushnumber(L, 42); return 1; } CORONA\_EXPORT int luaopen\_plugin\_magic(lua\_State \*L) { static const luaL\_Reg kVTable[] = { { "doSomething", doSomething }, { NULL, NULL } }; luaL\_openlib( L, "plugin.magic", kVTable, 0 ); return 1; }

If you don’t have Corona Enterprise, you can just build Lua libraries with lua.h and luauxlib.h. Here what that code would look like:

#include "lua.h" #include "lauxlib.h" int doSomething(lua\_State \*L) { lua\_pushnumber(L, 42); return 1; } #if \_\_cplusplus #define EXTERN extern "C" #else #define EXTERN extern #endif #if ( defined( \_WIN32 ) || defined( \_WIN64 ) ) #define CORONA\_DECORATOR EXTERN \_\_declspec( dllexport ) #else #define CORONA\_DECORATOR EXTERN \_\_attribute\_\_((visibility("default"))) #endif CORONA\_DECORATOR int luaopen\_plugin\_magic(lua\_State \*L) { static const luaL\_Reg kVTable[] = { { "doSomething", doSomething }, { NULL, NULL } }; luaL\_openlib( L, "plugin.magic", kVTable, 0 ); return 1; }

Now these are very specific examples and you would have to have a C/C++ interface to the SDK. And of course the thing your are building has to be available for the platform. For instance Facebook does not have a Windows or OS X SDK. They only have Android and iOS.

We assume our Enterprise developers have a working knowledge of Xcode and Visual Studio with regards to how to setup projects, link in 3rd party libraries, etc. We don’t have anything at the moment that would help someone not familiar with these environments to get them going. I believe one of our engineers is going to try and create some templates for this to help getting people less familiar with the environment going. No ETA because he has to work that in to his already deep task list.

Rob

There is additional discussion on building Windows plugins here:

https://forums.coronalabs.com/topic/57623-support-for-nativenewtextfield/?p=298499

Rob

Hi i am try to the sample above working. I seem to be running into an error, 

Screen%20Shot%202016-07-20%20at%2010.27.

I used the same code above and used the non enterprise version. 

Sounds like whatever you did to build the dylib didn’t work. There is an error about it being to short, which sounds like something didn’t get linked in that it needed. Perhaps so googling of that specific error might help.

Rob

Hi i am try to the sample above working. I seem to be running into an error, 

Screen%20Shot%202016-07-20%20at%2010.27.

I used the same code above and used the non enterprise version. 

Sounds like whatever you did to build the dylib didn’t work. There is an error about it being to short, which sounds like something didn’t get linked in that it needed. Perhaps so googling of that specific error might help.

Rob