如何在LUA 5.2.3中正确地将LUA_NUMBER从Double更改为浮动
How to change lua_number from double to float properly in Lua 5.2.3
我希望lua_number获得浮标,而不是double。我知道我必须在luaconf.h中更改一些东西,但我不知道什么。我正在使用LUA 5.2.3和Visual Studio C 。
您需要编辑luaconf.h
并更改以下内容:
-
LUA_NUMBER
tofloat
-
LUA_NUMBER_SCAN
to"%f"
-
LUA_NUMBER_FMT
至"%.7g"
-
l_mathop(x)
到(x##f)
-
lua_str2number
使用strtof
对于最后两个,您可能需要一个支持C99标准的C编译器。
in luaconf.h
/*
** {==================================================================
@@ LUA_NUMBER is the type of numbers in Lua.
** CHANGE the following definitions only if you want to build Lua
** with a number type different from double. You may also need to
** change lua_number2int & lua_number2integer.
** ===================================================================
*/
#define LUA_NUMBER_DOUBLE
#define LUA_NUMBER double
这实际上是Lua 5.1 luaconf,但是5.2 conf应该相似。
相关文章:
- C++在数学计算中将double转换为int
- C++Lua用户数据扰乱了Mathfu浮点值
- 在c++中为double类型的数组创建一个unique_ptr
- vector<vector<double>> to mxArray using memcpy
- (double) 和 double() 之间的区别
- C++标准是否允许<double>在没有开销的情况下实现 std::可选
- 使用 LuaBridge 或 Lua 将对象传递给 Lua 函数C++
- C++ Version Of Double.longBitsToDouble
- 错误:类型"double()"和"double()"的操作数无效到二进制&quo
- 有没有办法在C++的赋值中将"char**"转换为"double"?
- 为什么 nlohmann/json 序列化 "null" 而不是在 double 上"0"?
- 使用 std::vector<double> 访问由 std::unique_ptr<double[2] 管理的数据>
- 将 std::vector<double> 从 C++ 包装到 C 以在 Swift 中使用
- 将 Lua 函数块转换为 C 字符串
- 错误:无法将"<lambda(double)>"转换为"double(*)(double)"
- 我可以从 lua 5.0.2 加载用 c++ 编写的 lua 5.3.5 dll 吗?
- 使用 lua 协程 API 和lua_close时出现分段错误
- 使用 C++ 自动 Lua 绑定
- 调用 lua 函数的地址为 C/C++?
- 如何在LUA 5.2.3中正确地将LUA_NUMBER从Double更改为浮动