Cocos2d-x 3.2 Lua project through LuaSQLite3 using Sqlite3 issues Summary

Source: Internet
Author: User
Tags documentation lua

First explain the environment

Cocos2d-x v3.2

Why use this version because I was not at the client's decision-making point when the project started, because I was engaged in the server, so I can only continue to follow this version, at least this project is

Windows 7 64-bit Visual Studio 2013

This development environment, after the test of this need, let me more and more disappointed


Here is a description of the requirements

Very simple program, do not say, need to have a configuration management module, such as how much you do, now how many levels, the data is not many, always can not set the configuration file format, parsing and so on, with Userdefalut bar, too immature of a thing, although used, but this time still want to try something new, SQLite lightweight database.

Please take the time to look at my experience, perhaps save you a few hours later, perhaps there is a solution to your problem

The requirements are clear, I always have to operate sqlite in the LUA layer, this has open source module: Http://lua.sqlite.org/index.cgi/index

To be familiar with an open source project, be sure to start with the documentation, which is mentioned in the installation section of its documentation.

Luarocks (http://luarocks.org/) is the preferred mechanism to build and install lsqlite3; It assumes a SQLite3 library is already installed.

The general meaning is that it recommended you to install Lsqlite3 with luarocks, note oh, this name also pits me for a long time, and then again

Here we can only start to learn luarocks, now I understand it is that it is a tool to manage the Lua open source module, you can use it to quickly install open source modules, such as I used LUA encapsulated network module, submitted to Luarocks, So that others can quickly download and install into his operating system, and even the project does not have to introduce such operations, but this is really imperfect on windows, and even then I do not how, I do, Put the luarocks compiled DLL file directly into the sibling directory of my project executable file, the Mac will be a lot of installed files directly in the environment variables exist in the directory, regardless of the description of his document Luarocks always quickly loaded into their own operating system.

After that, you can install lsqlite3 with the command provided by Luarocks, about that named pit, I want to say here, if you install through this command: Luarocks installed luasql-sqlite3 You are wrong, you should install through this command, Luarocks install lsqlite3 That's what you really need. About the name pit is there for you to experience.

The installation process on Windows needs to specify Sqlite_dir Sqlite_incdir, according to the name of the meaning of the correct directory is good, so the need for you to download the Sqlite3 official website to compile a copy of the static library. method is not in detail said. If this step on the MAC is not necessary to make library directory, the practice told me, hehe. Here also to mention, you will see Cocos has made good sqlite3 library files, and header files, in Xxx\frameworks\cocos2d-x\external\sqlite3, it is best not to use that, because you lsqlite3 download the latest version of the, Your sqlite3 but not the latest version, the compilation process will report a wrong, this error is very difficult to let you think because of the version mismatch caused.

Even if you pass all the above sharpening, you will still be at the last step, stop. Because you have to pack, you have DLL files, you also have so files, but that are used by the operating system, the phone can not use it, the practice tells me, even if I put so file as a resource package on Android, the path is good, I still can not use it, too many attempts and friends, Let my previous efforts have died, your dynamic library is compiled with GCC, even if your mobile phone program can be loaded, also cannot use, must be compiled with the NDK, regardless of the method, this step is indispensable.

In fact, to support the operation of SQLite in the project, the original is not so troublesome, and now I will now use the method to say again

First you should read this article: http://blog.csdn.net/costa100/article/details/20050561

It encrypts related operations, you can temporarily ignore, the main operation is very similar, I write my detailed practice here

Create the Lsqlite3 directory in the project directory Xxx\frameworks\cocos2d-x\external\lua for the reason of the version

Unzip (each is the latest version downloaded on the official website)

Lsqlite3_fsl09w.zip

Sqlite-amalgamation-201507231639.zip

The extracted source files and header files

Sqlite3ext.h

Sqlite3.h

Sqlite3.c

Lsqlite3.c

Copy to Folder

Create a new lsqlite3.h header file in the directory

#ifndef __lsqlite3_h__#define __lsqlite3_h__#include "lauxlib.h" Lualib_api int luaopen_lsqlite3 (lua_state *L); #endif
Modify the Lsqlite3.c file to add the following two lines, including the newly created header file and the Sqlite3 header file

#include "lsqlite3.h" #include "sqlite3.h"

Modify the Xxx\frameworks\cocos2d-x\cocos\scripting\lua-bindings\manual\lua_extensions.c file and modify the following

#include "luasocket/luasocket.h" #include "luasocket/mime.h" #include "lsqlite3/lsqlite3.h" Static Lual_reg luax_exts[ ] = {{    "Socket.core", Luaopen_socket_core},    {"Mime.core", luaopen_mime_core},{"Lsqlite3", Luaopen_lsqlite3} ,    {null, null}};

Open the solution in VS2013, find the Liblua project, create a new lsqlite filter, add-existing items, add the header files and source files in the new directory Lsqlite3, build the project, there should be no problems. In fact, if you do not pack and cross-platform (how possible) you can also do so, you do not have to download sqlite3, directly with the COCOS2DX provided by the sqlite3 version, Xxx\frameworks\cocos2d-x\external\sqlite3, This requires you to include sqlite3.h in the Lsqlite3.cpp directory to change, at this time, your Liblua project can only add lsqlite3.h and lsqlite3.cpp files, so Liblua can be compiled through, but when compiling our project will be reported sqlite3 function is undefined, and a view is missing a library reference. Add a library reference to our project. So the program will compile properly.

This time if packaging, my Android bag used Cocos compile method, first of all, if using the second solution above, packaging is certainly very difficult, at least I have no plan, Because I do not know how to facilitate the introduction of sqlite3 in the android.mk dynamic link library, even if the introduction I think there should be a lot of pits, so it is always wise to start putting sqlite3 into their projects, when the command line is compiled, will be error, because you have not added your new source files to the Andro ID.MK, after the addition should not have any big problem.

          .. /.. /.. /external/lua/lsqlite3/lsqlite3.c.           /.. /.. /EXTERNAL/LUA/LSQLITE3/SQLITE3.C \

My summary of the article is generally written afterwards, so I may sometimes only focus on the key operations, some small problems, Baidu, think about the solution to the things, I may not how to write, because have forgotten, hope forgive me



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Cocos2d-x 3.2 Lua project through LuaSQLite3 using Sqlite3 issues Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.