如何在LUA 5.2.3中正确地将LUA_NUMBER从Double更改为浮动

How to change lua_number from double to float properly in Lua 5.2.3

本文关键字:LUA Double NUMBER 正确地      更新时间:2023-10-16

我希望lua_number获得浮标,而不是double。我知道我必须在luaconf.h中更改一些东西,但我不知道什么。我正在使用LUA 5.2.3和Visual Studio C 。

您需要编辑luaconf.h并更改以下内容:

  • LUA_NUMBER to float
  • 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应该相似。