corona

Parse parameters out of URL in Lua

戏子无情 提交于 2019-12-01 23:02:16
I have a URL and would like to parse its Parameter out of it, like: function unescape (s) s = string.gsub(s, "+", " ") s = string.gsub(s, "%%(%x%x)", function (h) return string.char(tonumber(h, 16)) end) return s end function parseurl (s,param) for k, v in string.gmatch( s, "([^&=?]+)=([^&=?]+)" ) do --t[k] = v if k == param then --print (k.." "..v) return unescape(v) end end s = "http://www.page.com/link.php uname=Hans+Testmann&uemail=myemail%40gmail.com&utext=Now+this+is+working+great.%0D%0A++&mdt=1#&mydays:themeupload"s Than I would call it and get Results like after --> parseurl (s, "uname

Why length is different in Lua

為{幸葍}努か 提交于 2019-12-01 21:51:31
I'm learning Lua for corona sdk and I have these local type1 = {nil, "(", nil, "x" ,nil , ")" ; n=6} local type2 = {"(",nil, "x",nil, ")",nil ; n=6} print(#type1) --prints 6 print(#type2) --prints 3 why the second one is not 6 too?? The # operator doesn't work on every table, it works only on a sequence, that is, the set of its positive numeric keys is equal to {1..n} for some integer n . In that case, n is its length. For instance, local t = {"hello", 42, true} is a sequence. But both your tables are not sequence because they have "holes" of nil . See Lua 5.2 Reference Manual: The length

method for serializing lua tables

走远了吗. 提交于 2019-12-01 15:59:18
问题 I may have missed this, but is there a built-in method for serializing/deserializing lua tables to text files and vice versa? I had a pair of methods in place to do this on a lua table with fixed format (e.g. 3 columns of data with 5 rows). Is there a way to do this on lua tables with any arbitrary format? For an example, given this lua table: local scenes={ {name="scnSplash", obj={ { name="bg", type="background", path="scnSplash_bg.png", }, { name="bird", type="image", path="scnSplash_bird

Background infinite using corona sdk

倾然丶 夕夏残阳落幕 提交于 2019-12-01 13:46:18
I'm trying to scroll side a background in corona sdk (infinity background) I used two images repeated (854x176). I tried this function: function mov(self, event) if self.x < -854 then self.x = 854 else self.x = self.x - self.speed end end it's working just fine but the problem that a small white space occurred between repetitions. Is there a better way to do this? One way of doing this would be to take advantage of Graphics 2.0 Engine's feature called repeating fills. Here are the steps: Set the default texture wrapping mode for x (you could do the same for y too): display.setDefault(

Integrate an Android app (.apk) into an existing Android project

倾然丶 夕夏残阳落幕 提交于 2019-11-30 18:20:10
Here's the use case: A friend and I are building an Android app and along with it want to integrate a game. The core of the app has been built in Eclipse but we are looking into building the game with an app building tool like Google AppInventer ( http://appinventor.googlelabs.com/about/ ) or Corona ( http://www.anscamobile.com/corona/ ). We'd like the existing app we've built to have a button like "Play Game" which will launch the game we build using one of these utilities. However when I messed around with Google App Inventor I noticed that I could only export the project as a .apk, which

In Lua, how do you find out the key an object is stored in?

人盡茶涼 提交于 2019-11-30 09:23:36
问题 How would you print() out or find out the index of an object? For example, if I spawned 20 random rock objects on screen into an array RockTable = {}; Like this RockTable[#RockTable + 1] = rock; And all 20 rocks are displayed on screen how would I find out what key or index each rock has by clicking on them? I'm using Corona SDK. Any help would be greatly appreciated. 回答1: Invert the table: function table_invert(t) local u = { } for k, v in pairs(t) do u[v] = k end return u end You can then

Integrate an Android app (.apk) into an existing Android project

你离开我真会死。 提交于 2019-11-30 02:11:29
问题 Here's the use case: A friend and I are building an Android app and along with it want to integrate a game. The core of the app has been built in Eclipse but we are looking into building the game with an app building tool like Google AppInventer (http://appinventor.googlelabs.com/about/) or Corona (http://www.anscamobile.com/corona/). We'd like the existing app we've built to have a button like "Play Game" which will launch the game we build using one of these utilities. However when I messed

Load Lua-files by relative path

只谈情不闲聊 提交于 2019-11-29 21:22:11
If I have a file structure like this: ./main.lua ./mylib/mylib.lua ./mylib/mylib-utils.lua ./mylib/mylib-helpers.lua ./mylib/mylib-other-stuff.lua From main.lua the file mylib.lua can be loaded with full path require('mylib.mylib') . But inside mylib.lua I would also like to load other necessary modules and I don't feel like always specifying the full path (e.g. mylib.mylib-utils ). If I ever decide to move the folder I'm going to have a lot of search and replace. Is there a way to use just the relative part of the path? UPD. I'm using Lua with Corona SDK, if that matters. There is a way of

Requesting JSON information from API. Corona

南楼画角 提交于 2019-11-29 17:15:53
I'm trying to make an app where I will gather information from a json api http://pool-x.eu/api , and print information easly bo choosing parameter. What is the easiest way to print each of the informations? Was thinking something in the way of making the information a string, and then request each of the parameters that way, but I don't know if that's the way to do it. here's a sample code to decode the json data i just happen to make a json text file out if the link you gave and decode it hope it helps local json = require "json" local txt local path = system.pathForFile( "json.txt", system

Forward define a function in Lua?

白昼怎懂夜的黑 提交于 2019-11-29 05:32:57
How do I call a function that needs to be called from above its creation? I read something about forward declarations, but Google isn't being helpful in this case. What is the correct syntax for this? Lua is a dynamic language and functions are just a kind of value that can be called with the () operator. So you don't really need to forward declare the function so much as make sure that the variable in scope when you call it is the variable you think it is. This is not an issue at all for global variables containing functions, since the global environment is the default place to look to