OK! This is a step-by-step tutorial to deploy your C++ plugins to the desktop player.
Having 0 experience in developing for Windows, I almost went insane trying to build dll files. I hope Someone finds this useful.
1.
Install Visual C++ Almost all the tutorials I found recommended using Visual C++ to build dlls. Maybe there are other ways, but I used Visual C++ 2010 Express Edition.
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express2.
Install Lua Lua installation is not needed(I think) if you can add your C++ header files into the project yourself. But I find this method a hell of a lot easier. I used Lua for Windows.
http://code.google.com/p/luaforwindows/downloads/detail?name=LuaForWindows_v5.1.4-45.exe&can=2&q=3.
Add Gideros Header Files to Lua .Again this is not compulsory. Just makes things easier
> Download the sample BitOp Library from this link
http://giderosmobile.com/forum/uploads/FileUpload/a0/29cdedc9a3ecc63ba1608c9a88992b.zip > Extract the rar file to a folder
> Inside the extracted folder, navigate to BitOp/jni/ folder
> Copy gexport.lua, gfile.lua, gideros.lua, gplugin.lua, gproxy.lua and greferenced.lua
> Go to the Lua installation folder (Mine was C:\Program Files\Lua\5.1/)
> Paste the copied files into the include folder (C:\Program Files\Lua\5.1\include)
4.
Create a New Dll Project in Visual C++ 2010 Express Edition > Open Visual C++ 2010 Express Edition
> Choose FILE --> NEW --> PROJECT
> In the New Project window, select WIN32 --> WIN32 CONSOLE APPLICATION. Enter a name for the project and also a name for the solution. Click OK
> A Win32 Application Wizard opens. Click Next.
> Choose APPLICATION TYPE as DLL and select EMPTY PROJECT. Click FINISH.
> A Project is created
5.
Add plugin code in C++ > Right Click on SOURCE FILES --> ADD --> NEW ITEM
> In the window that opens, select C++ FILE, enter a name for the file and click OK
> A blank C++ document is added. Add your code there.
> Let us use the sample plugin code found in
https://docs.google.com/document/pub?id=149g_P1YlE4_6v_hHbFx3YAaYpdU0HoM70XJSLTE38ww#h.fv5ug2ke945wCopy and the paste the code in the C++ file.
#include "gideros.h"
#include "lua.h"
#include "lauxlib.h"
static int addTwoIntegers(lua_State *L)
{
//retrieve the two integers from the stack
int firstInteger = lua_tointeger(L, -1);
int secondInteger = lua_tointeger(L, -2);
int result = firstInteger + secondInteger;
//place the result on the stack
lua_pushinteger(L, result);
//one item off the top of the stack, the result, is returned
return 1;
}
static int loader(lua_State *L)
{
//This is a list of functions that can be called from Lua
const luaL_Reg functionlist[] = {
{"addTwoIntegers", addTwoIntegers},
{NULL, NULL},
};
luaL_register(L, "myFirstPlugin", functionlist);
//return the pointer to the plugin
return 1;
}
static void g_initializePlugin(lua_State* L)
{
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
lua_pushcfunction(L, loader);
lua_setfield(L, -2, "myFirst");
lua_pop(L, 2);
}
static void g_deinitializePlugin(lua_State *L)
{ }
REGISTER_PLUGIN("myFirstPlugin", "1.0") |
6.
Add Lua librarites to the project. The following are the steps.
> Go to Lua Installation Directory
> Navigate to /lib/ folder ( in my system C:\Program Files\Lua\5.1\lib)
> Copy the files Lua5.1.dll and Lua5.1.lib
> Navigate to your project directory and paste the copied files there. (make sure you paste the files in the correct directory. If the .cpp file which you created is in there, then that is your project directory)
7.
Add external dependencies and incude directory to the project > Right Click on Project and select Properties.
> Select Configuration Options --> VC++ Directories. Add the following path in INCLUDE DIRECTORIES
[Lua Installation Directory]\include ( in my case C:\Program Files\Lua\5.1\include)
> Select Configuration Properties --> Linker --> Input. Add "lua5.1.lib" (without quotes) to Additional Dependencies
8.
Build the project > Right Click on the Created C++ file and select BUILD . See if the C++ file comiles without errors.
> Right Click on the Project and click BUILD. If everything goes well, you will see the message
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
> The path of the new dll file will also be displayed along with the above message. Go to the path and Copy the dll file.
9.
Include the created dll file > Go to Gideros Installation Directory
> Paste the copied dll file (the one copied in Step 8) into the Plugins directory(in my case C:\Program Files\Gideros\Plugins)
10.
Call the plugin from Gideros Desktop player > Open Gideros and create a new Project. Create a main.lua
> In the main.lua include the following code
require "myFirst"
local result = myFirstPlugin.addTwoIntegers(14, 48)
print("\n\nSample 1 - Result of addTwoIntegers:", result, "\n\n") |
> if
Sample 1 - Result of addTwoIntegers: 62 is printed in the console, then the plugin has been successfully inported and called from the desktop player.
Thats it! Its quite a tedious process if you're doing this for the first time. And I have explained more in detail than necessary so bear with me. if you encounter any difficulties, please comment below
Cheers!
Comments
The dll file is created and copied to the "C:\Program Files (x86)\Gideros\Plugins" folder. If I copy the dll to the "C:\Program Files (x86)\Gideros\" folder then I get a different error The project is called myFirst, I even called the cpp file myFirst.cpp and yet the problem persists. I'm running Gideros Studio v2012.2.2.1
This problem persists if I build a debug or release module. I really would like to get this working as it would save no end of time for what I'm trying to do.
Dislikes: seppsepp
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
Have attached my dll. See if that works for you.
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
I want to do a dll extension to run in script lua embedded on aplications that support LUA scripts, my doubt is:
Is your tutorial usefull to create a dll for function mentioned above without use of Gederos?
how can i create a dll in msvc++ 2010 xpress to run with require funtion on LUA script on windows 7?
thanks
tiago@thiengo.com
on windows with visual c++ i had the same error of @scouser.
...I am a bit 'discouraged ... (
www.tntengine.com
Here are the steps I usually follow:
1. Download Qt from http://qt.nokia.com/downloads/ For windows, we'll be mostly using mingw and qmake, not Qt libraries. And I recommend to download offline installer (1.7 GB).
2. Install it. But I use Qt only for desktop development. Therefore I deselect all the components related to mobile development (I've attached a screenshot)
3. Add the paths qmake.exe and mingw32-make.exe's paths to the PATH environment variable. On my computer these paths are:
5. Open a command line, go to C:\Temp\All Plugins\BitOp\source and type qmake and then mingw32-make
If everything builds correctly, now you're ready to make modifications on BitOp and make your own plugin.
when i go home i'll test!
ps: is possible to call from c code native gideros functions (non gfx function ex: getBounds?)
thanks!
www.tntengine.com
a little example ? "> (I mean calling gideros function from c code...)
just installed (in win7) the qt-mingw system and now i can create (win desktop) plugins !!!! wow!
PS: which project template do you use in QTCreator ?
in bitop
you use
-------------------
QT -= core gui
TEMPLATE = lib
-------------------
but i can't find in project templates...
Dislikes: Yan
www.tntengine.com
qmake has a couple of predefined templates like "lib" or "app" as described here: http://doc.qt.nokia.com/qmake-variable-reference.html#template here "lib" is used for creating dynamic libraries
i'm working hard this days trying to create new library for "fast" collision detection (bbox, obbox and circle collision) (without using box2d) using native code (where needed) and integrate into my animation system.
for now (thanks to your suggestion) i successfully created plugin for windows (dll) and for mac... next step will be create libs for ios and andorid!
I think I'll make "torrents" of questions next days!!! o->
get ready! ~O)
www.tntengine.com
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
I download the qt from http://releases.qt-project.org/qt4/source/qt-mac-opensource-4.8.4.dmg
and for step 5 I run qmake and then open the generated Xcode project and build it and got an libmd5.dylib file
but after I run it in the mac player ,it says
./md5.lua:22: loop or previous error loading module 'md5'
stack traceback:
I can run the code on the device player
What steps am I missing?
https://sites.google.com/site/xraystudiogame
#include "gideros.h"
#include "lua.h"
#include "lauxlib.h"
extern "C" {
LUALIB_API int luaopen_md5_core(lua_State *L);
}
static void g_initializePlugin(lua_State *L)
{
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
lua_pushcfunction(L, luaopen_md5_core);
lua_setfield(L, -2, "md5");
lua_pop(L, 2);
}
static void g_deinitializePlugin(lua_State *L)
{
}
REGISTER_PLUGIN("MD5", "1.0")
https://sites.google.com/site/xraystudiogame
1. did you copy libmd5.dylib to Plugins folder?
2. can you execute otool -L libmd5.dylib and write the output here?
Today,I build the bitop and copied the libbitop.dylib,it simply says
main.lua:80: module 'bit' not found:
the libmd5.dylib and libbitop.dylib file are compiled by myself, and the bitop.dylib is the original one(this one works).
the libbitop.dylib file is copied from /Users/zhengyi/Library/Developer/Xcode/DerivedData/bitop-fpvmasurgekilzdckjgdcwrgmcbq/Build/Products/Debug
zhengyimatoMacBook-Pro:Documents zhengyi$ otool -L libmd5.dylib
libmd5.dylib:
/usr/local/lib/libmd5.dylib (compatibility version 1.0.0, current version 1.0.0)
liblua.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
zhengyimatoMacBook-Pro:Documents zhengyi$ otool -L libbitop.dylib
libbitop.dylib:
/usr/local/lib/libbitop.dylib (compatibility version 1.0.0, current version 1.0.0)
liblua.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
zhengyimatoMacBook-Pro:Documents zhengyi$ otool -L bitop.dylib
bitop.dylib:
libbitop.1.dylib (compatibility version 1.0.0, current version 1.0.0)
@executable_path/../Frameworks/liblua.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
https://sites.google.com/site/xraystudiogame
I can not figure out what's wrong on mac. (
https://sites.google.com/site/xraystudiogame
If you look at bitop.pro, there is a line at the end of it:
install_name_tool -change liblua.1.dylib "@executable_path/../Frameworks/liblua.1.dylib" libmd5.dylib
the final libmd5.dylib works.
is anything wrong in my final step:
step 5 I run qmake and then open the generated Xcode project to build it and got an libmd5.dylib file
My pro file:
QT -= core gui
TARGET = md5
TEMPLATE = lib
INCLUDEPATH += ../../../Sdk/include
SOURCES += \
md5lib.c \
md5.c \
md5_stub.cpp \
HEADERS +=
LIBS += -L"../../../Sdk/lib/desktop" -llua
macx {
QMAKE_POST_LINK += install_name_tool -change liblua.1.dylib "@executable_path/../Frameworks/liblua.1.dylib" $(TARGET);
}
https://sites.google.com/site/xraystudiogame
And as a side note, if you're working with dynamic libraries on Mac, you need to use install_name_tool and otool -L a lot.
I will take some time to be familiar with these tools.
https://sites.google.com/site/xraystudiogame
Here's how I got bitop working on my mac
From the terminal type:
1. cd /Applications/Gideros Studio/All Plugins/BitOp/source
2. /Users/evs/QtSDK/Desktop/Qt/4.8.1/gcc/bin/qmake bitop.pro (where your qmake is)
3. make
4. copy libbitop.1.0.0.dylib to /Applications/Gideros Studio/Plugins
In your Gideros Studio project add:
evs
On the other way, i tried to do with QT as atilim said. It's a bit confusing because i found a QT 5.5 version withg qmake and minggw32-make files. I use the BitOp project example provided by Gideros. qmake generate the Makefiles in right way. But i got several errors when try to use mingw32-make. I reviewed the plugin process and i understand the BitOp technique in order to create comunication with Gideros Lua, but getting this problems on generating the right DLL file could be frustating.
Any recomendations updated? Maybe the tutorials are too old. I'm using Windows 8.1 and Gideros 20915.09
The second part depends on what errors do you get, maybe it is the problem with steam SDK, that their code is not mingw compatible, for example