title: Test if Lua number is integer or float
body: <p>In my C++ program, I need to know if a Lua variable is an integer number or a floating-point number. The C API provides <code>lua_isnumber()</code> but this function does not distinguish between <code>int/float/double</code>.</p>
  
  <p>So far I have worked around this by using <code>modf()</code>:</p>
  
  <pre><code>if (lua_isnumber(luaCtx, -1)) // int / unsigned int / float:
  {
      luaVarName = lua_tostring(luaCtx, -2);
      double n = static_cast&lt;double&gt;(lua_tonumber(luaCtx, -1));
  
      // Figure out if int or float:
      double fractPart, intPart;
      fractPart = modf(n, &amp;intPart);
  
      if (fractPart != 0.0)
      {
          luaVarType = ScriptVar::TypeTag::Float;
          luaVarData.asFloat = static_cast&lt;float&gt;(n);
      }
      else
      {
          luaVarType = ScriptVar::TypeTag::Integer;
          luaVarData.asInteger = static_cast&lt;int&gt;(n);
      }
  }
  </code></pre>
  
  <p>Does the Lua API provide a way to infer the variable type more precisely?</p>