cocos2dx 加入lpack库
发布时间:2020-12-14 17:18:34 所属栏目:百科 来源:网络整理
导读:在cocos2d_lua_bindings项目的external目录下建立lpack目录 1. lpack目录中增加lpack.c 从https://github.com/LuaDist/lpack获取 2. lpack目录增加lpack.h #ifndef LPACK_H #define LPACK_H // // lpack.h // cocos2d_lua_bindings // // Created by sherloc
在cocos2d_lua_bindings项目的external目录下建立lpack目录 1. lpack目录中增加lpack.c从https://github.com/LuaDist/lpack获取 2. lpack目录增加lpack.h#ifndef LPACK_H
#define LPACK_H
//
// lpack.h
// cocos2d_lua_bindings
//
// Created by sherlock on 2017/3/6.
//
//
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "tolua++.h"
#ifdef __cplusplus
}
#endif
TOLUA_API int luaopen_pack(lua_State *L);
#endif /* LPACK_H */
3. 在manual/network/lua_extensions.c中增加如下内容//增加引用文件
#include "external/lua/lpack/lpack.h"
static luaL_Reg luax_exts[] = {
{"socket.core",luaopen_socket_core},{"mime.core",luaopen_mime_core},{"pack",luaopen_pack},//添加包到脚本系统
{NULL,NULL}
};
4. 测试local pack = require"pack"
--
local function hex(s)
local s=string.gsub(s,"(.)",function (x) return string.format("%02X",string.byte(x)) end)
return s
end
--
local bpack = string.pack
local a = bpack("Ab8"," 27Lua",5*16+1,0,1,4,8,0)
print(hex(a),string.len(a))
结论:基本思路是:c++通过tolua绑定到lua中使用 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |