Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should we use lua_pushinteger()?

Tags:

lua

The current versions of Lua don't support integer numbers, only floats. (With the upcoming 5.3 this is changing, but let's ignore this.)

So, my question is: what use there is in lua_pushinteger()? If the numbers get cast into a float, why not use lua_pushnumber() directly?

(Please don't answer "for future compatibility with 5.3", which is a good answer for today but is an answer that otherwise doesn't satisfy my curisoty: integer support wasn't expected in the old days. I want to know the reason lua_pushinteger() was introduced in the first place, not apologetic in hindsight.)

like image 764
Niccolo M. Avatar asked Jun 12 '14 12:06

Niccolo M.


1 Answers

The explicit handling of integers in the API was introduced for documentation, performance, and correctness.

Concentrating the handling of integers explicitly inside the API allows the core to use the best conversion to and from floats; in some platforms, this can be costly if done naively. It also allows the core to check for overflow, though Lua 5.1 and 5.2 did not check this.

like image 90
lhf Avatar answered Nov 04 '22 05:11

lhf