1 Star 0 Fork 1

xuenguang/luawrapper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
utility.h 3.19 KB
一键复制 编辑 原始数据 按行查看 历史
sniperHW 提交于 2018-03-06 13:39 . none
/*
Copyright (C) <2012> <huangweilook@21cn.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _UTILITY
#define _UTILITY
#include "TypeList.h"
#include "Trait.h"
template<typename T>
struct GetReplaceType
{
typedef T type;
//typedef typename refTraits<T>::RefType type;
};
template<>
struct GetReplaceType<const char *>
{
typedef std::string type;
};
template<>
struct GetReplaceType<char *>
{
typedef std::string type;
};
template<typename T>
struct GetRawType
{
typedef T type;
};
template<typename T>
struct GetRawType<T&>
{
typedef T &type;
};
template<>
struct GetRawType<std::string>
{
typedef const char * type;
};
template<typename T>
inline typename GetRawType<T>::type GetRawValue(T &in)
{
return in;
}
template<>
inline GetRawType<std::string>::type GetRawValue(std::string &in)
{
return in.c_str();
}
static inline const char *stack_value_tostr(lua_State *L,int index) {
static char buff[1024];
int type = lua_type(L,index);
switch(type) {
case LUA_TNIL:{
snprintf(buff,1023,"nil");
}break;
case LUA_TUSERDATA:{
snprintf(buff,1023,"userdata");
}break;
case LUA_TLIGHTUSERDATA:{
snprintf(buff,1023,"lightuserdata");
}break;
case LUA_TNUMBER:{
lua_Number v = lua_tonumber(L,index);
if(v != (lua_Integer)v){
snprintf(buff,1023,"%f",v);
} else {
snprintf(buff,1023,"%lld",lua_tointeger(L,index));
}
}break;
case LUA_TBOOLEAN:{
lua_Integer b = lua_tointeger(L,index);
snprintf(buff,1023,"%s",b == 1 ? "true":"false");
}break;
case LUA_TTABLE:{
snprintf(buff,1023,"table");
}break;
case LUA_TTHREAD:{
snprintf(buff,1023,"thread");
}break;
case LUA_TFUNCTION:{
snprintf(buff,1023,"function");
}break;
case LUA_TSTRING:{
snprintf(buff,1023,"%s",lua_tostring(L,index));
}
break;
default:{
snprintf(buff,1023,"unknow");
}
}
buff[1023] = 0;
return buff;
}
static inline void show_stack(lua_State *L,const char *msg = NULL) {
int top = lua_gettop(L);
if(msg) {
printf("top:%d,%s\n",top,msg);
}else {
printf("top:%d\n",top);
}
int i;
for(i = top;i > 0; --i) {
if(i == top) {
printf("(stack index:%d) %s <- top\n",i,stack_value_tostr(L,i));
} else {
printf("(stack index:%d) %s\n",i,stack_value_tostr(L,i));
}
}
}
#endif
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/a13173091052/luawrapper.git
git@gitee.com:a13173091052/luawrapper.git
a13173091052
luawrapper
luawrapper
master

搜索帮助