/
lua.html
115 lines (90 loc) · 3.01 KB
/
lua.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<!-- Code example from The Crash Course to Lua http://luatut.com/crash_course.html
And GameMinion https://github.com/GameMinion/GM-Corona-SDK/blob/master/gameminion.lua
-->
<meta charset=utf-8>
<title>Syntax Highlighting</title>
<link href="../themes/css/blackboard.css" rel="stylesheet" type="text/css" media="screen">
<body>
<pre>
<code data-language="lua">
function get_all_factors(number)
--[[--
Gets all of the factors of a given number
@Parameter: number
The number to find the factors of
@Returns: A table of factors of the number
--]]--
local factors = {}
for possible_factor=1, math.sqrt(number), 1 do
local remainder = number%possible_factor
if remainder == 0 then
local factor, factor_pair = possible_factor, number/possible_factor
table.insert(factors, factor)
if factor ~= factor_pair then
table.insert(factors, factor_pair)
end
end
end
hello = nil -- This is it!
hello = 3%2
print("I haz "..#bag_of_stuff.." things")
table.sort(factors)
return factors
end
--The Meaning of the Universe is 42. Let's find all of the factors driving the Universe.
the_universe = 42
factors_of_the_universe = get_all_factors(the_universe)
--Print out each factor
print("Count", "The Factors of Life, the Universe, and Everything")
table.foreach(factors_of_the_universe, print)
-- Other example
-------------------------------------------------
-- PUBLIC FUNCTIONS
-------------------------------------------------
function gameminion.init(accessKey, secretKey) -- constructor
-- initialize GM connection
GM_ACCESS_KEY = accessKey
GM_SECRET_KEY = secretKey
local newGameminion = {
authToken = authToken,
accessKey = GM_ACCESS_KEY,
secretKey = GM_SECRET_KEY,
gameID = "4f6f1e456b789d0001000002",
cloudStorageBox = cloudStorageBox,
gameminion = gameminion
}
return setmetatable( newGameminion, gameminion_mt )
end
-------------------------------------------------
-- User
-------------------------------------------------
function gameminion:loginWeb()
local authToken
return authToken
end
-------------------------------------------------
function gameminion:loginAPI(username, password)
local params = "login="..username.."&password="..password"
local path = "user_sessions/user_login.json"
-- set AuthToken when it gets it
local function networkListener(event)
if (event.isError) then
print("Network Error")
print("Error: "..event.response)
return false
else
self.authToken = json.decode(event.response).auth_token
print("User Logged In!")
print("Auth Token: "..self.authToken)
return true
end
end
postGM(path, params, networkListener)
return true
end
</code>
</pre>
<script src="../dist/rainbow.js"></script>
<script src="../src/language/lua.js"></script>
</body>