display in config.lua

Here is our config.lua

local aspectRatio = display.pixelHeight / display.pixelWidth -- background size: width = 640\*1.125=720, height = 960\*1,1875=1140 application = { content = { width = aspectRatio \> 1.5 and 640 or math.ceil( 960 / aspectRatio ), height = aspectRatio \< 1.5 and 960 or math.ceil( 640 \* aspectRatio ), -- width = 640, --height = 960, scale = "letterBox", fps = 60, launchPad = false, }, }

When compiling for OSX there is an error:

attempt to index global display (a nil value)

Is there no display for OS X ?

I don’t believe desktop builds have access to the display object when config.lua is processed.

Rob

It’s a false positive.  What’s happening is that the OS X desktop app will read the “config.lua” file *before* it creates the desktop window and before it creates the Corona runtime (which provides the Corona Lua APIs) in order to determine what the desktop window’s pixel width and height should be.  So, any Corona Lua APIs in the “config.lua” will trigger a harmless Lua runtime error at first.  We’ll then make a best guess at what the window width and height should be based on your “build.settings” file, create the desktop window and Corona runtime, and then read the “config.lua” file 1 more time… at which point, our Corona Lua APIs become available.  Corona’s Win32 desktop apps will do the same thing.

Bottom line: It’s a chicken & egg issue.  We need to read your “config.lua” file to determine what the pixel width and height of the window should be, which of course means the display.* Lua APIs can’t be ready for you to use since the pixel width and height you want to read haven’t been determined yet.

If you want to get rid of the error, then a simple solution is to check for the display library/table’s existence before using it.  I’ve posted a similar solution via the link below…

   https://forums.coronalabs.com/topic/62568-blured-images-in-win32-app/?p=324852

I don’t believe desktop builds have access to the display object when config.lua is processed.

Rob

It’s a false positive.  What’s happening is that the OS X desktop app will read the “config.lua” file *before* it creates the desktop window and before it creates the Corona runtime (which provides the Corona Lua APIs) in order to determine what the desktop window’s pixel width and height should be.  So, any Corona Lua APIs in the “config.lua” will trigger a harmless Lua runtime error at first.  We’ll then make a best guess at what the window width and height should be based on your “build.settings” file, create the desktop window and Corona runtime, and then read the “config.lua” file 1 more time… at which point, our Corona Lua APIs become available.  Corona’s Win32 desktop apps will do the same thing.

Bottom line: It’s a chicken & egg issue.  We need to read your “config.lua” file to determine what the pixel width and height of the window should be, which of course means the display.* Lua APIs can’t be ready for you to use since the pixel width and height you want to read haven’t been determined yet.

If you want to get rid of the error, then a simple solution is to check for the display library/table’s existence before using it.  I’ve posted a similar solution via the link below…

   https://forums.coronalabs.com/topic/62568-blured-images-in-win32-app/?p=324852