trumanzhao / luna Goto Github PK
View Code? Open in Web Editor NEW基于C++17的lua/C++绑定库,以及lua的二进制序列化等辅助代码
License: MIT License
基于C++17的lua/C++绑定库,以及lua的二进制序列化等辅助代码
License: MIT License
函数调用结束后,没有把返回结果pop出来。几个类似的函数都存在相同的问题。
template <typename... ret_types, typename... arg_types>
bool lua_call_table_function(lua_State* L, std::string* err, const char table[], const char function[], std::tuple<ret_types&...>&& rets, arg_types... args) {
lua_get_table_function(L, table, function);
int _[] = { 0, (native_to_lua(L, args), 0)... };
if (!lua_call_function(L, err, sizeof...(arg_types), sizeof...(ret_types)))
return false;
lua_to_native_mutil(L, rets, std::make_index_sequence<sizeof...(ret_types)>());
return true;
}
当pcall失败,return false前没有把errstring 和debug.traceback pop出来,会导致栈溢出。
bool lua_call_function(lua_State* L, std::string* err, int arg_count, int ret_count) {
int func_idx = lua_gettop(L) - arg_count;
if (func_idx <= 0 || !lua_isfunction(L, func_idx))
return false;
lua_getglobal(L, "debug");
lua_getfield(L, -1, "traceback");
lua_remove(L, -2); // remove 'debug'
lua_insert(L, func_idx);
if (lua_pcall(L, arg_count, ret_count, func_idx)) {
if (err != nullptr) {
*err = lua_tostring(L, -1);
}
return false;
}
lua_remove(L, -ret_count - 1); // remove 'traceback'
return true;
}
考虑解码函数
if (number & 0x1)
{
number >>= 1;
number = ~number;
number++;
}
else
{
number >>= 1;
}
当number = 0时,有结果= 0
当number = 1时,有结果= ~(1 >> 1) + 1 = 0xFFFFFFFF + 1 = 0
建议参照Zigzag编码修改对有符号整数的编解码。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.