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

Problematic behavior with preprocessor not showing the actual error #287

Open
stefanos82 opened this issue Jan 8, 2025 · 0 comments
Open

Comments

@stefanos82
Copy link
Contributor

I'm working on a simple demo and when I run the code, it returned me this confusing output:

image

Here's the code:

require 'io'
require 'string'

local FOREGROUND <comptime> = 38
local BACKGROUND <comptime> = 48

local function color_range(first: integer, last, anyground: integer)
  local resetdefault: string = "\x1b[0m"
  local resetwithspace: string = "\x1b[0m "

  local resetoutput = resetwithspace
  for color = first, last do
    if color % 16 == 0 then
      io.printf("\n")
    end
    if color == last then
      resetoutput = resetdefault
    end

    io.printf(string.format("\x1b[%d;5;%dm%3d%s", anyground, color, color, resetoutput))
  end
end

io.printf("\x1b[1;39m0 to 255 Colors (FOREGROUND)\x1b[22;0m\n")
color_range(0, 255, FOREGROUND)
io.printf("\n\n")

io.printf("\x1b[1;39m0 to 255 Colors (BACKGROUND)\x1b[22;0m\n")
color_range(0, 255, BACKGROUND)
io.printf("\n\n")

In case you are wondering what's the catch, it's the darn last; I forgot to declare it as integer and the compiler tried to interpret it as any.

It took me some time disabling my io.printf()s to isolate the behavior.

When a similar issue pops up, what is your suggestion to detect it as soon as possible?

Am I supposed to use a flag or some kind of internal trick to isolate the problematic code?

Can we do something about it @edubart ?

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

1 participant