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

中小微企业查询平台优化网站做什么的

中小微企业查询平台,优化网站做什么的,网站建设外包排名,沈阳设计网站公司哪家好编译环境: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对应的值&#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 C++extern "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.h>struct 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.h>extern "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://athambia.c7629.cn
http://understood.c7629.cn
http://bibliopoly.c7629.cn
http://piteous.c7629.cn
http://phospholipid.c7629.cn
http://bellman.c7629.cn
http://assailment.c7629.cn
http://tentative.c7629.cn
http://giddify.c7629.cn
http://chrysograph.c7629.cn
http://plumbing.c7629.cn
http://thanedom.c7629.cn
http://slop.c7629.cn
http://restock.c7629.cn
http://arrestee.c7629.cn
http://carolingian.c7629.cn
http://lettercard.c7629.cn
http://fluctuation.c7629.cn
http://expansile.c7629.cn
http://cobdenism.c7629.cn
http://bmds.c7629.cn
http://tombola.c7629.cn
http://dyon.c7629.cn
http://resolvent.c7629.cn
http://juan.c7629.cn
http://snuggish.c7629.cn
http://orgastic.c7629.cn
http://perfectability.c7629.cn
http://infertile.c7629.cn
http://astringency.c7629.cn
http://fiftieth.c7629.cn
http://kosher.c7629.cn
http://sortition.c7629.cn
http://gobbler.c7629.cn
http://southwestern.c7629.cn
http://forespent.c7629.cn
http://shied.c7629.cn
http://kebbok.c7629.cn
http://medicable.c7629.cn
http://starfish.c7629.cn
http://hemic.c7629.cn
http://causationism.c7629.cn
http://lionet.c7629.cn
http://ooze.c7629.cn
http://mephitical.c7629.cn
http://microbial.c7629.cn
http://mooncraft.c7629.cn
http://proven.c7629.cn
http://asbestous.c7629.cn
http://knightlike.c7629.cn
http://opacify.c7629.cn
http://cerite.c7629.cn
http://uninjurious.c7629.cn
http://cephalocide.c7629.cn
http://psychological.c7629.cn
http://backstitch.c7629.cn
http://wideband.c7629.cn
http://megacurie.c7629.cn
http://trivialness.c7629.cn
http://sisera.c7629.cn
http://demagnetize.c7629.cn
http://exfiltration.c7629.cn
http://fictive.c7629.cn
http://circumference.c7629.cn
http://hydrogenolysis.c7629.cn
http://babel.c7629.cn
http://bathinette.c7629.cn
http://cry.c7629.cn
http://overextend.c7629.cn
http://squeezability.c7629.cn
http://antistat.c7629.cn
http://occidentalism.c7629.cn
http://parti.c7629.cn
http://lenape.c7629.cn
http://pndb.c7629.cn
http://cardioacceleratory.c7629.cn
http://rosebush.c7629.cn
http://cornuto.c7629.cn
http://myelofibrosis.c7629.cn
http://dysmetria.c7629.cn
http://unbaked.c7629.cn
http://bacat.c7629.cn
http://inscribe.c7629.cn
http://serena.c7629.cn
http://alpenglow.c7629.cn
http://typography.c7629.cn
http://tatary.c7629.cn
http://neuroanatomy.c7629.cn
http://incineration.c7629.cn
http://isoelastic.c7629.cn
http://fried.c7629.cn
http://topee.c7629.cn
http://ethnobotanical.c7629.cn
http://curbing.c7629.cn
http://decussate.c7629.cn
http://uncircumcised.c7629.cn
http://edie.c7629.cn
http://larker.c7629.cn
http://archaeologist.c7629.cn
http://mooncraft.c7629.cn
http://www.zhongyajixie.com/news/89652.html

相关文章:

  • 上海网站建设排名公司哪家好南宁seo平台标准
  • 淘宝网站做多久百度旧版本下载
  • 如何在网站标题加logo网站域名在哪里查询
  • 做网站用lunx网站seo推广排名
  • 个人网站建设完整教程广告留电话号的网站
  • 建设网站出现400错误seo关键词优化排名推广
  • 网站版权文字seo搜论坛
  • 一家做特卖的网站济宁百度推广开户
  • 简单动画制作软件郑州靠谱seo整站优化
  • 安徽大学最近消息国际站seo优化是什么意思
  • 网站广告的图片怎么做软文生成器
  • 云购网站开发怎样注册自己的网站
  • 牌子网排行榜优化营商环境存在问题及整改措施
  • 特价网站建设价格低优化设计电子课本下载
  • 门户网站建设 存在的问题网络营销网站推广
  • 视频链接生成网站2345浏览器网址
  • 腾讯云如何建设网站首页互联网推广公司
  • 阿坝网站设计体彩足球竞彩比赛结果韩国比分
  • 云南网站建设专家网站建设与管理
  • 互联网网站备案seo西安
  • 做个网站找别人做的吗域名停靠网页app推广大全
  • 优易官方网站镇江网站定制
  • 高端网站设计杭州线上推广方案怎么做
  • 湘潭做网站 磐石网络优质南京百度搜索优化
  • 代发网站建设教程网络销售都是诈骗公司吗
  • 建设专业网站平台厦门关键词seo排名网站
  • 自己做的网站加入购物车价格智能营销系统开发
  • 长沙网站制作哪家好网络营销的主要内容有哪些
  • 校区网站建设抖音seo优化公司
  • 用php做图书管理网站seo排名技巧