Value:tonumber( ) method

Converts the C Value to a Lua number or to a Lua integer if the value fits in it.

Notes

Number conversion will work only with the numerical C types :
  • "char", "unsigned char", "wchar_t"
  • "short", "unsigned short"
  • "int", "unsigned int", "bool"
  • "long", "unsigned long"
  • "long long", "unsigned long long"
  • "long long", "unsigned long long"
  • "float", "double"
  • "int16_t", "unsigned int16_t"
  • "int32_t", "unsigned int32_t"
  • "int64_t", "unsigned int64_t"
  • "size_t"

Return value

Returns a number representation of the C Value.

Example

local c = require "c" -- Create a Value that contains a C integer value initialized to 125 local c_int = c.int(125) -- Converts the C integer Value to a Lua number, and prints it print(c_int:tonumber())