cocos2dx Lua專案中新增Sqlite

2021-06-21 02:49:31 字數 1759 閱讀 5272

1. 使用版本cocos2dx2.2.2 + vs2012,建立lua專案後,發現沒有sqlite,將新增的記錄寫下來:

建立lsqlite3.h

#ifndef _lua_sqlite3_h_

#define _lua_sqlite3_h_

#include "lauxlib.h"

lualib_api int luaopen_lsqlite3(lua_state *l);

#endif /* ifndef _sqlite3rtree_h_ */

然後隨便找個地方輸入ccluastack, 按f12,進入 cpp檔案

在bool ccluastack::init(void)前面新增:

#if __cplusplus

extern "c" ,

};#if __cplusplus

}#endif

然後在bool ccluastack::init(void)中修改**:

// register our version of the global "print" function

const lual_reg global_functions = ,

};lual_register(m_state, "_g", global_functions);

lual_reg *lib = luax_my_libs;

lua_getglobal(m_state,"package");

lua_getfield(m_state,-1,"preload");

for (;lib->func;lib++)

lua_pop(m_state,2);

tolua_cocostudio_open(m_state);

然後編譯的時候,發現會報錯

1>e:\cocos2d-x-2.2.2\cocos2d-x-2.2.2\projects\planeluagame\classes\lsqlite3.c(1275): error c2275: 「lua_number」: 將此型別用作表示式非法

1> e:\cocos2d-x-2.2.2\cocos2d-x-2.2.2\scripting\lua\lua\lua.h(99) : 參見「lua_number」的宣告

1>e:\cocos2d-x-2.2.2\cocos2d-x-2.2.2\projects\planeluagame\classes\lsqlite3.c(1275): error c2146: 語法錯誤: 缺少「;」(在識別符號「n」的前面)

1>e:\cocos2d-x-2.2.2\cocos2d-x-2.2.2\projects\planeluagame\classes\lsqlite3.c(1275): error c2065: 「n」: 未宣告的識別符號

1>e:\cocos2d-x-2.2.2\cocos2d-x-2.2.2\projects\planeluagame\classes\lsqlite3.c(1276): error c2065: 「n」: 未宣告的識別符號

1>e:\cocos2d-x-2.2.2\cocos2d-x-2.2.2\projects\planeluagame\classes\lsqlite3.c(1277): error c2065: 「n」: 未宣告的識別符號

修改lua_number, 在**前面先宣告乙個 lua_number n, 然後在使用 就可以了

Cocos2d x Lua示例專案HelloLua

cocos2d x lua示例專案hellolua 本篇部落格介紹cocos2d x中lua的例項專案,就是使用cocos2d x建立的初始專案執行所呈現的農場,這裡筆者取名為hellolua。本篇部落格會詳細在 中解析cocos2d x 3.1.1建立的lua專案中例項,一些api的使用。注 本示...

Cocos2d x Lua基本操作

1.lua庫引用 目錄新增 lua lua luajit include lib新增 lua51.lib 2.開啟lua庫 示例 lua state pl lua open luaopen base pl luaopen math pl luaopen string pl 3.讀取lua值 示例 1...

cocos2dx lua優化總結

渲染效率 紋理格式 執行效率 記憶體 包大小 cpp view plain copy 安卓啟用4444紋理 iftargetplatform cc.platform os android then cc.texture2d setdefaultalphapixelformat cc.texture2...