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

I want lua_number to get a float instead of a double. I know that I need to change something in luaconf.h, but I do not know what. I am using Lua 5.2.3 and Visual Studio C ++.

+6
source share
2 answers

You need to edit luaconf.h and change them:

  • LUA_NUMBER to float
  • LUA_NUMBER_SCAN to "%f"
  • LUA_NUMBER_FMT to "%.7g"
  • l_mathop(x) to (x##f)
  • lua_str2number to use strtof

For the last two, you probably need a C compiler that supports (some of) the C99 standard.

+9
source

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 

This is actually Lua 5.1 luaconf, but 5.2 conf should be similar.

+2
source

All Articles