Sam
Sam

Reputation: 128

Can anyone identify the programming language of this code snippet?

I have been trying to create an Android application to control various appliances using the IR blaster on my phone. As a starting point, I wanted to get the pulses used by another application, namely Xiaomi's "Mi Remote" application.

I installed the app, and copied the app's data from the /data directory on Android. I managed to find an SQLite database containing the frequency and pulse information for my appliance. It was stored as a code snippet, like the following. Can anyone identify what language this is?

if(exts~=nil) then
timing_on=exts[9] 
timing_off=exts[10] 
bytes1={}  
for i=1,9,1 do bytes1[i]=bytes[i] bytes1[i+9]=bytes[i] end 
bytes1[13]=0x60 
if(((timing_on==0)or(timing_on==nil))and((timing_off==0) or(timing_off==nil)))then return  end
if(timing_on~=nil)and(timing_on>0) then
if(timing_on<600) then 
    if(timing_on%60==0) then 
        bytes1[2]=(bytes1[2]&0x0F)+0x80 
        else bytes1[2]=(bytes1[2]&0x0F)+0x90 
            end 
elseif(timing_on>=600)and(timing_on<1200) then 
    if(timing_on%60==0) then
        bytes1[2]=(bytes[2]&0x0F)+0xA0 
        else bytes1[2]=(bytes1[2]&0x0F)+0xB0  
            end
elseif(timing_on>=1200) then 
    if(timing_on%60==0) then 
        bytes[2]=(bytes1[2]&0x0F)+0xC0  
        else bytes1[2]=(bytes1[2]&0x0F)+0xD0 
            end 
end
bytes1[3]=bytes1[3]+math.floor((timing_on\/60)%10) 
bytes1[9]=(((bytes1[1]&0x0F)+(bytes1[2]&0x0F)+(bytes1[3]&0x0F)+(bytes1[4]&0x0F)+(bytes1[6]>>4)+0x0C)<<4) 
bytes1[11]=bytes1[2] 
bytes1[12]=bytes1[3] 
bytes1[15]=(timing_on&0xFF) 
bytes1[16]=((timing_on>>8)&0x0F) 
bytes1[17]=0 
bytes1[18]=(((bytes1[9]>>4)+(bytes1[15]>>4)+(bytes1[16]>>4)+(bytes1[17]>>4)+0x0D)<<4)+0x02 
elseif(timing_off~=nil)and(timing_off>0)then
    if(timing_off<600) then 
        if(timing_off%60==0) then 
            bytes1[2]=(bytes1[2]&0x0F)+0x80  
            else 
            bytes1[2]=(bytes1[2]&0x0F)+0x90 
            end 
    elseif(timing_off>=600)and(timing_off<1200) then 
        if(timing_off%60==0) then 
            bytes1[2]=(bytes1[2]&0x0F)+0xA0  
            else bytes1[2]=(bytes1[2]&0x0F)+0xB0 
                end 
    elseif(timing_off)>=1200 then 
        if(timing_off%60==0) then 
            bytes1[2]=(bytes1[2]&0x0F)+0xC0 
            else bytes1[2]=(bytes1[2]&0x0F)+0xD0 
                end 
    end
    bytes1[3]=bytes1[3]+math.floor((timing_off\/60)%10) 
    bytes1[9]=(((bytes1[1]&0x0F)+(bytes1[2]&0x0F)+(bytes1[3]&0x0F)+(bytes1[4]&0x0F)+(bytes1[6]>>4)+0x0C)<<4) 
    bytes1[11]=bytes1[2] 
    bytes1[12]=bytes1[3] 
    bytes1[16]=((timing_off&0x0F)<<4) 
    bytes1[17]=(timing_off>>4) 
    bytes1[15]=0 
    bytes1[18]=(((bytes1[9]>>4)+(bytes1[15]>>4)+(bytes1[16]>>4)+(bytes1[17]>>4)+0x0D)<<4)+0x01 
end
bytes=bytes1 
end

Upvotes: 3

Views: 183

Answers (2)

Jay
Jay

Reputation: 3355

Looks like the programming language Lua, https://www.lua.org/

I can't tell if it's some type of dialect or not but it seems to be valid Lua which is creating the bytes which are associated with the infrared commands being sent.

the \/ portion seems to be some type of escape placed there because that is not a valid piece of Lua code afaik. (https://www.tutorialspoint.com/lua/lua_operators.htm).

See also what does lua operator ~= mean?

Upvotes: 1

Steve
Steve

Reputation: 90

It might be Lua. It has elseif and nil and a math library with a .floor() function.

Upvotes: 2

Related Questions