PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Demos/Color lines/bin/Data/Scripts/Common.lua

http://deku2d-engine.googlecode.com/
Lua | 357 lines | 336 code | 14 blank | 7 comment | 13 complexity | 3eceadef86b9de03382a32e85158d06f MD5 | raw file
  1. function dostring( source )
  2. return loadstring( source )()
  3. -- assert?
  4. end
  5. function LogHelper(...)
  6. local t = {...}
  7. local tempString = ''
  8. for i = 1,#t do
  9. tempString = tempString .. tostring(t[i]) .. "\t"
  10. end
  11. Log("LUA", tempString)
  12. end
  13. print = LogHelper
  14. function Dump(value, depth, done)
  15. done = done or {}
  16. depth = depth or 0
  17. if done[value] then
  18. return
  19. end
  20. done[value] = true
  21. local tabs = ("|\t"):rep(depth)
  22. if type(value) == "table" then
  23. for k, v in pairs(value) do
  24. print(tabs .. k, v)
  25. if type(v) == "table" then
  26. Dump(v, depth + 1, done)
  27. end
  28. end
  29. else
  30. print( tabs .. value)
  31. end
  32. end
  33. -- 2do: add memorization pattern in order to remember produced results
  34. -- The thing below is very stupid, so it doesn't any lexical analisys
  35. -- just simple plaint text iterative gsub
  36. Preprocessor = Preprocessor or
  37. {
  38. [ 'Set' ] = function ( self, name, text, ... )
  39. local info =
  40. {
  41. [ 'text' ] = text
  42. }
  43. local args = { ... }
  44. info.templates = {}
  45. for i = 1, #args do
  46. info.templates[ i ] = args[ i ]
  47. end
  48. self[ name ] = function ( self, ... )
  49. return self:Execute( name, ... )
  50. end
  51. self[ '__' .. name ] = info
  52. end,
  53. [ 'Get' ] = function ( self, name, ... )
  54. local info = self[ '__' .. name ]
  55. if not info then
  56. error( 'Specified function not found in preprocessor' )
  57. end
  58. local args = { ... }
  59. if #args ~= #info.templates then
  60. error( 'Supported arguments count doesn\'t correspond template specification' )
  61. end
  62. local substRes = info.text
  63. for i = 1, #args do
  64. substRes = substRes:gsub( info.templates[ i ], args[ i ] )
  65. end
  66. return loadstring( substRes )
  67. end,
  68. [ 'Execute' ] = function ( self, name, ... )
  69. return self.Get( self, name, ... )()
  70. end,
  71. }
  72. FSA = FSA or
  73. {
  74. [ 'Execute' ] = function( self, ... )
  75. if not self.state then
  76. error( 'FSA: state unspecified' )
  77. elseif not self[ self.state ] then
  78. error( string.format( 'State \'%s\' not found in FSA', self.state ) )
  79. end
  80. self[ self.state ]( ... )
  81. end,
  82. [ 'state' ] = nil,
  83. }
  84. --[[ CLASS ]]--
  85. local class_mt = {}
  86. Class =
  87. {
  88. Derive = function(self)
  89. local t = {}
  90. for k,v in pairs(self) do
  91. t[k] = v
  92. end
  93. setmetatable(t, getmetatable(self))
  94. return t
  95. end,
  96. }
  97. setmetatable(Class, class_mt)
  98. function GetObjectTable(object) -- userdata
  99. return _G[GetName(object)] or object
  100. end
  101. _GetObjectHelper = GetObject
  102. GetObject = function(name)
  103. return _G[name] or GetObjectTable(_GetObjectHelper(name))
  104. end
  105. --[[ Sorry, brothers, I wish, I could lazy enough to find a proper place for THAT: --]]--
  106. SDLK =
  107. {
  108. _UNKNOWN = 0,
  109. _FIRST = 0,
  110. _BACKSPACE = 8,
  111. _TAB = 9,
  112. _CLEAR = 12,
  113. _RETURN = 13,
  114. _PAUSE = 19,
  115. _ESCAPE = 27,
  116. _SPACE = 32,
  117. _EXCLAIM = 33,
  118. _QUOTEDBL = 34,
  119. _HASH = 35,
  120. _DOLLAR = 36,
  121. _AMPERSAND = 38,
  122. _QUOTE = 39,
  123. _LEFTPAREN = 40,
  124. _RIGHTPAREN = 41,
  125. _ASTERISK = 42,
  126. _PLUS = 43,
  127. _COMMA = 44,
  128. _MINUS = 45,
  129. _PERIOD = 46,
  130. _SLASH = 47,
  131. _0 = 48,
  132. _1 = 49,
  133. _2 = 50,
  134. _3 = 51,
  135. _4 = 52,
  136. _5 = 53,
  137. _6 = 54,
  138. _7 = 55,
  139. _8 = 56,
  140. _9 = 57,
  141. _COLON = 58,
  142. _SEMICOLON = 59,
  143. _LESS = 60,
  144. _EQUALS = 61,
  145. _GREATER = 62,
  146. _QUESTION = 63,
  147. _AT = 64,
  148. --Skip uppercase letters
  149. _LEFTBRACKET = 91,
  150. _BACKSLASH = 92,
  151. _RIGHTBRACKET = 93,
  152. _CARET = 94,
  153. _UNDERSCORE = 95,
  154. _BACKQUOTE = 96,
  155. _a = 97,
  156. _b = 98,
  157. _c = 99,
  158. _d = 100,
  159. _e = 101,
  160. _f = 102,
  161. _g = 103,
  162. _h = 104,
  163. _i = 105,
  164. _j = 106,
  165. _k = 107,
  166. _l = 108,
  167. _m = 109,
  168. _n = 110,
  169. _o = 111,
  170. _p = 112,
  171. _q = 113,
  172. _r = 114,
  173. _s = 115,
  174. _t = 116,
  175. _u = 117,
  176. _v = 118,
  177. _w = 119,
  178. _x = 120,
  179. _y = 121,
  180. _z = 122,
  181. _DELETE = 127,
  182. _WORLD_0 = 160,
  183. _WORLD_1 = 161,
  184. _WORLD_2 = 162,
  185. _WORLD_3 = 163,
  186. _WORLD_4 = 164,
  187. _WORLD_5 = 165,
  188. _WORLD_6 = 166,
  189. _WORLD_7 = 167,
  190. _WORLD_8 = 168,
  191. _WORLD_9 = 169,
  192. _WORLD_10 = 170,
  193. _WORLD_11 = 171,
  194. _WORLD_12 = 172,
  195. _WORLD_13 = 173,
  196. _WORLD_14 = 174,
  197. _WORLD_15 = 175,
  198. _WORLD_16 = 176,
  199. _WORLD_17 = 177,
  200. _WORLD_18 = 178,
  201. _WORLD_19 = 179,
  202. _WORLD_20 = 180,
  203. _WORLD_21 = 181,
  204. _WORLD_22 = 182,
  205. _WORLD_23 = 183,
  206. _WORLD_24 = 184,
  207. _WORLD_25 = 185,
  208. _WORLD_26 = 186,
  209. _WORLD_27 = 187,
  210. _WORLD_28 = 188,
  211. _WORLD_29 = 189,
  212. _WORLD_30 = 190,
  213. _WORLD_31 = 191,
  214. _WORLD_32 = 192,
  215. _WORLD_33 = 193,
  216. _WORLD_34 = 194,
  217. _WORLD_35 = 195,
  218. _WORLD_36 = 196,
  219. _WORLD_37 = 197,
  220. _WORLD_38 = 198,
  221. _WORLD_39 = 199,
  222. _WORLD_40 = 200,
  223. _WORLD_41 = 201,
  224. _WORLD_42 = 202,
  225. _WORLD_43 = 203,
  226. _WORLD_44 = 204,
  227. _WORLD_45 = 205,
  228. _WORLD_46 = 206,
  229. _WORLD_47 = 207,
  230. _WORLD_48 = 208,
  231. _WORLD_49 = 209,
  232. _WORLD_50 = 210,
  233. _WORLD_51 = 211,
  234. _WORLD_52 = 212,
  235. _WORLD_53 = 213,
  236. _WORLD_54 = 214,
  237. _WORLD_55 = 215,
  238. _WORLD_56 = 216,
  239. _WORLD_57 = 217,
  240. _WORLD_58 = 218,
  241. _WORLD_59 = 219,
  242. _WORLD_60 = 220,
  243. _WORLD_61 = 221,
  244. _WORLD_62 = 222,
  245. _WORLD_63 = 223,
  246. _WORLD_64 = 224,
  247. _WORLD_65 = 225,
  248. _WORLD_66 = 226,
  249. _WORLD_67 = 227,
  250. _WORLD_68 = 228,
  251. _WORLD_69 = 229,
  252. _WORLD_70 = 230,
  253. _WORLD_71 = 231,
  254. _WORLD_72 = 232,
  255. _WORLD_73 = 233,
  256. _WORLD_74 = 234,
  257. _WORLD_75 = 235,
  258. _WORLD_76 = 236,
  259. _WORLD_77 = 237,
  260. _WORLD_78 = 238,
  261. _WORLD_79 = 239,
  262. _WORLD_80 = 240,
  263. _WORLD_81 = 241,
  264. _WORLD_82 = 242,
  265. _WORLD_83 = 243,
  266. _WORLD_84 = 244,
  267. _WORLD_85 = 245,
  268. _WORLD_86 = 246,
  269. _WORLD_87 = 247,
  270. _WORLD_88 = 248,
  271. _WORLD_89 = 249,
  272. _WORLD_90 = 250,
  273. _WORLD_91 = 251,
  274. _WORLD_92 = 252,
  275. _WORLD_93 = 253,
  276. _WORLD_94 = 254,
  277. _WORLD_95 = 255,
  278. _KP0 = 256,
  279. _KP1 = 257,
  280. _KP2 = 258,
  281. _KP3 = 259,
  282. _KP4 = 260,
  283. _KP5 = 261,
  284. _KP6 = 262,
  285. _KP7 = 263,
  286. _KP8 = 264,
  287. _KP9 = 265,
  288. _KP_PERIOD = 266,
  289. _KP_DIVIDE = 267,
  290. _KP_MULTIPLY = 268,
  291. _KP_MINUS = 269,
  292. _KP_PLUS = 270,
  293. _KP_ENTER = 271,
  294. _KP_EQUALS = 272,
  295. _UP = 273,
  296. _DOWN = 274,
  297. _RIGHT = 275,
  298. _LEFT = 276,
  299. _INSERT = 277,
  300. _HOME = 278,
  301. _END = 279,
  302. _PAGEUP = 280,
  303. _PAGEDOWN = 281,
  304. _F1 = 282,
  305. _F2 = 283,
  306. _F3 = 284,
  307. _F4 = 285,
  308. _F5 = 286,
  309. _F6 = 287,
  310. _F7 = 288,
  311. _F8 = 289,
  312. _F9 = 290,
  313. _F10 = 291,
  314. _F11 = 292,
  315. _F12 = 293,
  316. _F13 = 294,
  317. _F14 = 295,
  318. _F15 = 296,
  319. _NUMLOCK = 300,
  320. _CAPSLOCK = 301,
  321. _SCROLLOCK = 302,
  322. _RSHIFT = 303,
  323. _LSHIFT = 304,
  324. _RCTRL = 305,
  325. _LCTRL = 306,
  326. _RALT = 307,
  327. _LALT = 308,
  328. _RMETA = 309,
  329. _LMETA = 310,
  330. _LSUPER = 311,
  331. _RSUPER = 312,
  332. _MODE = 313,
  333. _COMPOSE = 314,
  334. _HELP = 315,
  335. _PRINT = 316,
  336. _SYSREQ = 317,
  337. _BREAK = 318,
  338. _MENU = 319,
  339. _POWER = 320,
  340. _EURO = 321,
  341. _UNDO = 322,
  342. _LAST = 323,
  343. }