Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when key is huge int string #46

Open
freedom12 opened this issue Feb 14, 2023 · 1 comment
Open

error when key is huge int string #46

freedom12 opened this issue Feb 14, 2023 · 1 comment
Assignees

Comments

@freedom12
Copy link

local t = {
    ["1111111111111111111111111"] = true,
    ["foo"] = true
}
util.serpent.block(t)

errorKey = [string "util/serpent.lua"]:101: bad argument #1 to 'format' (number has no integer representation)
stack traceback:
[C]: in function 'string.format'
[string "util/serpent.lua"]:101: in function <[string "util/serpent.lua"]:100>
[C]: in function 'string.gsub'
[string "util/serpent.lua"]:107: in function <[string "util/serpent.lua"]:105>
[C]: in function 'table.sort'
[string "util/serpent.lua"]:103: in upvalue 'alphanumsort'
[string "util/serpent.lua"]:167: in local 'val2str'
[string "util/serpent.lua"]:219: in function <[string "util/serpent.lua"]:51>

@pkulchenko pkulchenko self-assigned this Jun 24, 2023
@pkulchenko
Copy link
Owner

@freedom12, you can set sortkeys option to false to disable key sorting or provide your own function that handles these values better.

BTW, what version of serpent are you using? I added the following test and it passed with the current serpent version (0.303):

  local key1 = "1111111111111111111111111"
  local a = { [key1] = true, ["foo"] = true}
  local f = assert(loadstring('return '..serpent.line(a)),
    "serializing table with a long numerical keys (as string): failed")
  local _a = f()
  assert(_a[key1] == true, "table with a long numerical key (as string): failed")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants