godot_luaAPI icon indicating copy to clipboard operation
godot_luaAPI copied to clipboard

Bug Report: Numbers returned from lua are always cast as floats

Open jbromberg opened this issue 10 months ago • 2 comments

Describe the bug When pushing an integer value to lua, it is always pulled back as a float.

To Reproduce Steps to reproduce the behavior:

var lua := LuaAPI.new()
var num: int = 10
lua.push_variant("num", num)
var pulled = lua.pull_variant("num")
print(typeof(pulled)) # float

Expected behavior The value should be of variant type integer.

jbromberg avatar Apr 25 '24 21:04 jbromberg

Lua does not have Integer, it only has number which is similar to float https://www.lua.org/pil/2.3.html

Supchik22 avatar Apr 26 '24 09:04 Supchik22

Godot supports integers though. This is what I'm currently doing in my project but it's a bit hacky:

if value is float and fmod(value, 1) == 0:
    value = int(value)

jbromberg avatar Apr 26 '24 19:04 jbromberg