Skip to content

Instantly share code, notes, and snippets.

@kgadek
Last active January 3, 2016 12:29
Show Gist options
  • Save kgadek/8463181 to your computer and use it in GitHub Desktop.
Save kgadek/8463181 to your computer and use it in GitHub Desktop.
Projekt Sauron: interfejs i przykładowy kod zadania typu `background_tasks`.
-- ---------------------------------------------------------------------------------------------------------------------
-- MOCK INTERFEJSU DOSTĘPNEGO NA APPCE
-- ---------------------------------------------------------------------------------------------------------------------
os = require "os"
local android = {}
function android.send(self, x)
print("ANDROID:SEND:", x)
end
function android.sleep(self, t)
print("ANDROID:SLEEP:", t)
os.execute("sleep "..tonumber(t))
end
function android.getLatitude(self)
local res = 20.019
print("ANDROID:GETLATITUDE >>", res)
return res
end
function android.getLongitude(self)
local res = 50.0655
print("ANDROID:GETLLONGITUDE >>", res)
return res
end
function android.getTime(self)
local res = os.time()
print("ANDROID:GETLLONGITUDE >>", res)
return res
end
-- ---------------------------------------------------------------------------------------------------------------------
-- uruchomienie zadania
-- ---------------------------------------------------------------------------------------------------------------------
function fib(x) return x<2 and x or fib(x-1)+fib(x-2) end
local n = 10
for i=0,n do
local res = fib(i)
android:send(tostring(res))
end
@kgadek
Copy link
Author

kgadek commented Jan 16, 2014

W odpowiedzi powinno pojawić się:

ANDROID:SEND:   0
ANDROID:SEND:   1
ANDROID:SEND:   1
ANDROID:SEND:   2
ANDROID:SEND:   3
ANDROID:SEND:   5
ANDROID:SEND:   8
ANDROID:SEND:   13
ANDROID:SEND:   21
ANDROID:SEND:   34
ANDROID:SEND:   55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment