当前位置: 首页 > news >正文

网站登录破解西安知名的集团门户网站建设公司

网站登录破解,西安知名的集团门户网站建设公司,亚马逊网站推广怎么做,赣州市资讯网编译环境#xff1a;Ubuntu16.04 64位 交叉编译工具#xff1a;arm-hisiv500-linux-gcc 文章目录 1. 项目背景2. lua开源版本选择3. 封装代码3.1 源码简介3.2 封装类3.2.1 头文件3.2.2 类的实现3.3.3 sample代码 1. 项目背景 使用lua脚本#xff0c;读取key对应的值#x… 编译环境Ubuntu16.04 64位 交叉编译工具arm-hisiv500-linux-gcc 文章目录 1. 项目背景2. lua开源版本选择3. 封装代码3.1 源码简介3.2 封装类3.2.1 头文件3.2.2 类的实现3.3.3 sample代码 1. 项目背景 使用lua脚本读取key对应的值用作设备的默认配置。 2. lua开源版本选择 使用lua-5.4.6.tar.gz点击下载早期使用lua-5.0.2.tar.gz在部分平台上存在浮点运算错误的问题放弃。 3. 封装代码 3.1 源码简介 源码的目录结构比较简单只有一个src目录Makefile略作修改即可或者根据自己项目做简化。 lua.hpp文件内容如下外部调用主要用到就是这三个头文件在编译C工程时注意extern “C” // lua.hpp // Lua header files for C // extern C not supplied automatically because Lua also compiles as Cextern C { #include lua.h #include lualib.h #include lauxlib.h } 3.2 封装类 3.2.1 头文件 #ifndef __LUA_CONFIG_H__ #define __LUA_CONFIG_H__#include string #include pthread.hstruct lua_State; typedef struct lua_State lua_State;class LuaConfig { public:static int Initialize(void);static int Invalidate(void);static LuaConfig* instance(void); private:static LuaConfig* s_instance;LuaConfig(void);virtual ~LuaConfig(void);LuaConfig(LuaConfig ); // 拷贝构造函数禁止拷贝public:int Init(const char * filename);//要解析的lua文件可以按照lua语法包含其他luavoid unInit();/// 根据传入的键值返回相应的字符串/// key为要访问的键值/// defaultValue为默认值当访问的键值不存在时返回std::string getString(const char * key, const char * defaultValue);/// 根据传入的键值返回相应的double值,与getString类似/// key为要访问的键值/// defaultValue为默认值当访问的键值不存在时返回double getNumber(const char * key, double defaultValue 0);private:int TravelTable(const char * key);private:lua_State *m_luastate;pthread_mutex_t m_Mutex; };#endif //__LUA_CONFIG_H__ 3.2.2 类的实现 #include LuaConfig.h #include string.h #include stdlib.hextern C {#include lua/lua.h#include lua/lauxlib.h#include lua/lualib.h };int LuaConfig::Initialize(void) {if(s_instance ! NULL)return -1;s_instance new LuaConfig;return 0; } int LuaConfig::Invalidate(void) {if(s_instance NULL)return 0;delete s_instance;return 0; } LuaConfig* LuaConfig::instance(void) {return s_instance; }LuaConfig* LuaConfig::s_instance NULL;LuaConfig::LuaConfig() {m_luastate NULL;pthread_mutex_init(m_Mutex, NULL); }LuaConfig::~LuaConfig() {unInit();pthread_mutex_destroy(m_Mutex); }int LuaConfig::Init(const char * filename) {if (m_luastate ! NULL)return -1;if (filename NULL)return -2; #if 0 // 5.0.2的封装m_luastate lua_open();if (m_luastate NULL)return -3;luaopen_base(m_luastate);luaopen_table(m_luastate);luaopen_io(m_luastate);luaopen_string(m_luastate);luaopen_math(m_luastate);luaopen_debug(m_luastate);//luaopen_lfs(m_luastate);//luaopen_bitlib(m_luastate);if (lua_dofile(m_luastate, filename) ! 0)return -4; #else//5.4.6m_luastate luaL_newstate();if (m_luastate NULL)return -3;luaL_openlibs(m_luastate);if (luaL_dofile(m_luastate, filename) ! 0)return -4; #endifreturn 0; }void LuaConfig::unInit() {if (m_luastate ! NULL){lua_close(m_luastate);m_luastate NULL;}return; }std::string LuaConfig::getString(const char * key, const char * defaultValue) {pthread_mutex_lock(m_Mutex);int nTop lua_gettop(m_luastate);int status TravelTable(key);std::string ret defaultValue;if( (status 0) (lua_isstring(m_luastate, -1))){ret lua_tostring(m_luastate, -1);}lua_settop(m_luastate, nTop);pthread_mutex_unlock(m_Mutex);return ret; }double LuaConfig::getNumber(const char * key, double defaultValue) {pthread_mutex_lock(m_Mutex);int nTop lua_gettop(m_luastate);int status TravelTable(key);double ret defaultValue;if( (status 0) (lua_isnumber(m_luastate, -1))){ret lua_tonumber(m_luastate, -1);}lua_settop(m_luastate, nTop);pthread_mutex_unlock(m_Mutex);return ret; }int LuaConfig::TravelTable(const char * key) {// 创建匿名函数int len strlen(key) 16;char* szFunc (char*)malloc(len);memset(szFunc, 0, len);sprintf(szFunc, return %s, key);int status luaL_loadbuffer(m_luastate, szFunc, strlen(szFunc), table_travel);if(status 0){status lua_pcall(m_luastate, 0, LUA_MULTRET, 0);}free(szFunc);return status; } 3.3.3 sample代码 LuaConfig::Initialize(); LuaConfig* pCfg LuaConfig::instance(); pCfg-Init(./test.lua);int testA (int)LuaConfig::instance()-getNumber(testA, 0); std::string testB LuaConfig::instance()-getString(testB, 123456);if (pCfg ! NULL) {pCfg-unInit();LuaConfig::Invalidate(); } 以上。 转载请注明出处如有错漏之处敬请指正。
http://www.hkea.cn/news/14357374/

相关文章:

  • 公司管理网站首页深圳网站公司招聘
  • 网站接入服务提供商短视频seo是什么
  • 安卓游戏模板下载网站公司网站怎么推广
  • 网站seo搜索引擎优化怎么做南宁公司官网建站
  • 闵行网站开发学校网站建设专业公司
  • 自己做的网站打不开是什么原因网站改版
  • 养老网站建设 中企动力宝安沙井天气
  • 写网站方案网站备案撤销怎么办
  • wordpress子目录网站网站建设与设计摘要
  • 做的比较好的官方网站网站开发和app开发哪个难
  • 该网站尚未备案 腾讯云站长工具seo综合查询可以访问
  • 郑州外贸网站建设哪家好常用的网络营销工具有哪些
  • 服装店网页设计网站模板企业网站开发服务
  • 邯郸做网站公司上海游戏公司排名
  • 厦门建设局网站水果网页设计代码
  • 高端网络公司网站源码做图书出版 外国网站
  • 电商支付网站建设费进什么科目深圳招聘网站排行
  • 国外展览设计网站帝国cms获取网站地址
  • 建设安全工程信息网站电子商务设计网站建设
  • 网站建设企业哪里好12306网站开发多少钱
  • 惠州网站建设报价wordpress 没有外观
  • 北京软装设计公司有哪些网络营销品牌策划优化
  • 浙江省建设培训中心的网站WordPress阿里云oos
  • 拥有自己的网站建站宝盒小程序
  • 深圳seo网站优化公司全国新农村建设网站
  • 网站后台管理界面html广州排名网站关键词优化
  • 兰州网站建设公互动平台怎么注册
  • 上海 松江 网站制作做羞羞的事的视频网站
  • 进入公众号平台360网站排名优化
  • 重庆做商城网站公司注册地址是营业执照上的地址吗