参与制作的游戏内部有导出sqlite数据为lua表的步骤,引擎用的cocos2d,但是每次都要启动游戏exe
坐旁边的策划小哥想在手机远程操作公司电脑配置提交数值表,他表示手机没法启动游戏exe,但我没有我们的游戏的工程文件,抄不了前人的代码就自己动手简单实现了一下
新建控制台工程,自己编译集成了sqlite与lua的lib导入,略过不写
sqlitedbtest.cpp
#include "pch.h"
#include "include/sqlite3.h"
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <direct.h>
extern "C" {
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
using namespace std;
sqlite3 * pDB = NULL;
lua_State *L;
string result = "";
int pram_count = 0;
char *path;
bool getWorkPath();
int getInfo();
bool dirExists(const std::string& dirName_in);
int luaGetDirExists(lua_State *L);
int SelectInfo(lua_State *L);
int luaTest();
int setFunc();
int clearFunc(lua_State *L);
char* func(char * const str);
static void print_error(lua_State *L);
int main()
{
getInfo();
system("pause");
}
bool getWorkPath()
{
//也可以将buffer作为输出参数
if ((path = _getcwd(NULL, 0)) == NULL)
{
perror("getcwd error");
return false;
}
else
{
printf("%s\n", path);
return true;
}
return false;
}
string GbkToUtf8(const char *src_str)
{
int len = MultiByteToWideChar(CP_ACP, 0, src_str, -1, NULL, 0);
wchar_t* wstr = new wchar_t[len + 1];
memset(wstr, 0, len + 1);
MultiByteToWideChar(CP_ACP, 0, src_str, -1, wstr, len);
len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
char* str = new char[len + 1];
memset(str, 0, len + 1);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
string strTemp = str;
if (wstr) delete[] wstr;
if (str) delete[] str;
return strTemp;
}
int getInfo()
{
if (!getWorkPath())
{
printf("get path err");
return 0;
}
string db_path(path);
db_path = db_path + "\\data.db";
printf("%s\n",db_path.c_str());
db_path = GbkToUtf8(db_path.c_str());
int nRes = sqlite3_open(db_path.c_str(), &pDB);
//string db_path = path + "/data.db";
//int nRes = sqlite3_open("E:/test/sqlitedbtest/sqlitedbtest/data.db", &pDB);
if (nRes != SQLITE_OK)
{
cout << "Open database fail: " << sqlite3_errmsg(pDB);
goto QUIT;
}
setFunc();