Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to handle platform specific code? — Gideros Forum

How to handle platform specific code?

Hi.
Let's say I have code specific for Android, iOS and HTML5.

As Lua doesn't have #ifdef, how do I handle it?

Thank you.

Comments

  • The top of each api command indicates which platforms support it
    https://wiki.giderosmobile.com/index.php/Accelerometer
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • hgy29hgy29 Maintainer
    If you use a function which isn’t available on some platform, you can call it inside a pcall() and check the result

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    Accepted Answer
    Here is an example for getDeviceInfo()...
    device={application:getDeviceInfo()}
    print(device[1])
    print(device[2])
    print(device[3])
    print(device[4])
    print(device[5])
    if device[5]=="TV" then tv=true end
    if device[1]=="Windows" or device[1]=="Mac OS" then
    	--application:set("cursor","blank")
    	pc=true
    	premium=true
    	application:setWindowSize(600,1024)
    	if not secret then
    		--application:setScaleMode("noScale")
    		--application:setWindowSize(600,1024)
    		application:setFullScreen(true)
    --	application:setScaleMode("letterbox")
    --	application:setOrientation("landscapeLeft")
    --	application:setFullScreen(true)
    	end
    	tv=true
    elseif device[1]=="Web" then
    	web=true premium=true
    	local url=JS.eval("window.location.href")
    	local line=find(url,"?")
    	if line then
    		params=parseUrl(sub(url,line+1))
    	end
    elseif device[1]=="Win32" then win32=true tv=true premium=true
    elseif device[1]=="WinRT" then winrt=true premium=true
    elseif device[1]=="Windows Phone" then winrt=true slow=true premium=true
    elseif device[1]=="Android" then android=true
    	if device[3]=="Amazon" then kindle=true
    		if sub(device[4],1,3)=="AFT" then tv=true if device[4]=="AFTM" then slow=true end end
    	elseif device[3]=="OUYA" then ouya=true tv=true slow=true
    	elseif device[3]=="Geniatech" then tv=true
    		if sub(device[4],1,9)=="GameStick" or device[4]=="TotoTV Stick" then gamestick=true slow=true end
    	elseif device[3]=="HardKernel Co., Ltd." then tv=true hardkernel=true
    		if device[4]=="ODROIDC" then odroidc=true slow=true end
    	elseif device[4]=="Nexus Player" then tv=true nexusplayer=true
    	elseif device[3]=="razer" then tv=true razer=true
    		if device[4]=="Forge" then forgetv=true end
    	elseif device[3]=="IRIVER" then slow=true end
    elseif device[1]=="iOS" then ios=true
    	if device[3]=="AppleTV" then tv=true appletv=true end
    end

    Likes: talis

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.