lua,corona , How to add touch and scroll event on a button on a top of scroll view Corona?

How to add touch and scroll event on a button on a top of scroll view Corona?


Tag: lua,corona

I'm creating level selection scene in corona. To accomplish this I have used scrollview and I have added a group of buttons to this scrollview.

But my problem is that I can scroll when I touch the background of the scrollview but I when I touch any of this button the scroll view didn't scroll.

What I need is to handle to events onpress on the button and scroll for the scroll view
so any ideas to how I can scroll the scroll view if I touch and hold on the button then I scrolled my finger?


I have solved my problem using takefocus method inside the button listener with this code

if ( phase == "moved" ) then
    local dy = math.abs( ( event.y - event.yStart ) )
    -- If the touch on the button has moved more than 10 pixels,
    -- pass focus back to the scroll view so it can continue scrolling
    if ( dy > 10 ) then
        scrollView:takeFocus( event )


Multiline function tables in lua

I cannot seem to find any other online help about creating a table which contains functions which are multiline. For example, here is a snippit of code from the lua wiki. action = { [1] = function (x) print(1) end, [2] = function (x) z = 5 end, ["nop"] =...

Nginx disable or decode url encoding when writing to access log

I have an open resty nginx with lua code that enhance the data and then I write this data to the access log for data analysis. The data that the lua code produce includes double quotes but nginx write it to the access log as \x22. Can I disable this...

iterating over a table passed as an argument to a function in lua

I am trying using the for _ in pairs() notation to iterate over a table within a function, but if I type anything, even gibberish like print('asdgfafs'), nested inside the for loop, it never gets printed. Code: record = {bid1,bid2,bid3} bid1 = {bidTime = 0.05,bidType = 'native'} bid2 = {bidTime...

Recursive loop stopping after a short time

Lua in ComputerCraft 1.5 This seems to work but the recursive loops is breaking after 4 or 5 times running. Cannot seem to see why. Am i doing something incredibly wrong here? Full Code Snippet for the loop: x = 1 function loop() if x > 0 then getTarg() derp1()...

Fast way to initialize a tensor in torch7

I need to initialize a 3D tensor with an index-dependent function in torch7, i.e. func = function(i,j,k) --i, j is the index of an element in the tensor return i*j*k --do operations within func which're dependent of i, j end then I initialize a 3D tensor A like this: for...

Erlang spawning large amounts of C processes

I've been looking into how I could embed languages (let's use Lua as an example) in Erlang. This of course isn't a new idea and there are many libraries out there that can do this. However I was wondering if it was possible to start a Genserver with state which...

Convolution Neural Network in torch. Error when training the network

I am trying to base my Convolution neural network upon the following tutorial: The issue is that my images are of different dimensions than those used in the tutorial. (3x200x200). Also I have only two classes. The following are the changes that I made : Changing the dataset to...

Lua import strings from file

I can't load my user.db into Lua. user.db contains: user1="XYZ1" user2="Xzy2" .... admin="ZXY" Some Bash and Python scripts use the same db. For Bash e.g. I used the source user.db command, but I don't have a clue for lua. Should be something similiar outside?! I tried the require function but...

Awesome desktop manager widgets

I came upon this problem before, but only now it really renders awesome desktop manager useless. I was searching how to connect to Wifi with awesome. Found Gigamo Wifi Widget. Cool, how do I eat it? The awesome wiki entry on widgets does not really answer this question. I know...

ROBLOX Lua Error in script: '=' expected near ''

Hello I am writing a scipt on ROBLOX and I have encountered a problem. function showVictoryMessage(playerName) local message ="Message") message.Text = playerName .." has won!" message.Parent = game.Workspace wait (2) message.Destroy() end Upon running this function, or more specifically the "message.Destroy" command, I get the error: Error in script:...

Lua search through table

I am working on a game project using Corona SDK and I am running into an issue. I am trying to use string.find() in a for loop to test to determine if a value is in a certain table and if so, add that value to another table. My problem...

horizontal movement in game (rotated player)

In my world I have a character wich is always rotated towards the mouse. It is very logical that when the player moves forward or backward, that the character's x coordinate equals it's x coordinate minus (or plus) the cosine of its x coordinate. And the same for its y...

Lua - Is it possible to check if 2 functions are equal?

Is it either possible to get the size of a function in bytes to see if it matches another function similar to C++ sizeof operator, or evaluate two functions some other way to see if they are both equal without actually knowing what the function/s are? Example: local function equals(func1,...

Write to file using Lua FFI

I am trying to use Lua FFI using LuaJIT to append some text to a file, but I am not very knowledgable of C, so I have some trouble. This is the code: local ffi = require "ffi" ffi.cdef[[ typedef int __kernel_ssize_t; typedef __kernel_ssize_t ssize_t; ssize_t write(int fildes, const void...

Lua in pairs with same order as it's written

Is there any way to loop trough a table like the one below in the same order as it's written? local tbl = { ["hello"] = 1, [2] = 2, [50] = 3, ["bye"] = 4, [200] = 5 } What I mean is that when I use "in pairs"...

Lua obfuscator, how to

I understand this question will appear silly but I'm clueless what to do, which makes it even more silly. I have written a lua script for a game - which works, but I've never actually run any lua with the lua programs(from the site download). I would like to obfuscate...

How can I convert a character code to a string character in Lua?

How can I convert a character code to a string character in Lua? E.g. d = 48 -- this is what I want str_d = "0" ...

Write lua_requiref in lua5.1

I would like to use the function lua_requiref, but in lua5.1. Is there a way to get the effect of lua_requiref in lua 5.1?...

Torch Lua: Why is my gradient descent not optimizing the error?

I've been trying to implement a siamese neural network in Torch/Lua, as I already explained here. Now I have my first implementation, that I suppose to be good. Unfortunately, I'm facing a problem: during training back-propagation, the gradient descent does not update the error. That is, it always computes the...

Supporting “recursive objects” in lua

I'm fairly new to lua and have the following problem with an assignment from a class: We currently extend lua to support objects and inheritance. The Syntax for that is Class{'MyClass', attribute1 = String, attribute2 = Number } Class{'MySubClass', MyClass, attribute3 = Number } This works perfectly fine. The real...

Trouble connecting to ESP8266 NodeMCU Server

I have been having trouble connecting to my ESP-01 Wifi module running NodeMCU. I have set up a simple server, but whenever I try to connect to the IP Address via my browser, my browser times out. I know I am making connection to the device because I can see...

Luarocks can't install a library

I want to install this library: I do luarocks search lua-dbus There are 0 results. sudo luarocks install lua-dbus doesn't install anything as well. The problem is only with this library, because I can search for other libraries on luarocks, for example luarocks search socket gives plenty of matches....

MAMP or Mac nginx MySQL Lua

I've recently purchased a Mac Mini with the only purpose of being a server. I'm a C programmer, learning Lua and Obj-C at the moment. I'm trying to set up a website, a kind of CV/Personal Promotion site. I've been looking at MAMP for a while however, I would like...

What does this warning mean in corona sdk console?

I am getting the following warning in corona sdk console whenever i run my game WARNING: Cannot create path for resource file 'level1.ccscene' b/c it doesn't exist ...

Run Lua script from Python

Suppose I have a Lua script that contains 2 functions. I would like to call each of these functions with some arguments from a Python script. I have seen tutorials on how to embed Lua code in Python and vice versa using Lunatic Python, however, my Lua functions to be...

Computercraft Evaluate and Execute relative to ticks

For the sake of writing fast turtle programs, I am wondering how, in relation to ticks, is code executed? Is there a tick penalty for executing functions or evaluating other Lua statements in addition to the time it takes the turtle to move? In other words, does it take the...

conditional assignment of multiple values

I've got a function that either can take two parameter, or calls another function to retreive these values(semi-defaults in that case). Let's say the first function looks like this: -- the actuall issue function: function foo( param_1, param_2 ) local bar_1, bar_2 = param_1, param_2 or getBar() -- make funny...

Lua C++ Table Iteration

I am having a slight confusion of how lua_next really works. User defines a table: a={["a1"]=20,["a2"]=30} I want to print this table with a C++ code: inline int lua_print(lua_State* L) { wxString wxReturnStr=wxEmptyString; wxString tempString=wxEmptyString; int nargs = lua_gettop(L); for (int i=1; i <= nargs; i++) { int type =...

Corona sdk random text

I`m have a problem because when i touch my button sometimes not appear my text... (Sorry for my English!) Code: function randomText(event) display.remove(mmDis) local a = {"Cristiano ronaldo jest najlepszy!","messi jest dobry!","lewandowski jest ok","diego lopez to bramkarz realu"} com = (a[math.random(1,#a)]) local mmDis = display.newText(tostring(com), display.contentWidth*0.57, display.contentHeight*0.7, display.contentWidth*0.9, display.contentHeight*0.8, "Impact",...

Call download lua script in app

I am trying to develop a game by using the c++ with lua, and I am using the quick-cocos2d-x engine to help me finish that. The problem is: I need user to download the lua scripts into their sdcard on their iphone/android devices, so that I can call the function...

How do I do user inputs on the same line in Lua?

Here is my code: while true do opr = txt = if opr == "print" then print(txt) else print("wat") end end What I'm trying to do is make it where you type print and then whatever you want like this: print text And it'll print text but I...

Lua error loading module 'libpng' (Torch, MacOSX)

How do I make libpng load properly in Lua? I am running Lua/Torch in iTorch Notebook in Mac OSX 10.10.3, where other basic functions in Lua work, such as plotting and calculations. brew install libpng Warning: libpng-1.6.17 already installed If I run: require 'nn'; require 'image'; itorch.image(image.lena()) error loading module...

lua - table.concat with string keys

I'm having a problem with lua's table.concat, and suspect it is just my ignorance, but cannot find a verbose answer to why I'm getting this behavior. > t1 = {"foo", "bar", "nod"} > t2 = {["foo"]="one", ["bar"]="two", ["nod"]="yes"} > table.concat(t1) foobarnod > table.concat(t2) The table.concat run on t2 provides no...

Corona : score keep running/ save it and show it after

My score doesn't stop when my main object hits an obstacle (keeps running on the storyboard restart and start screen). I want it to stop and be able to save it and show it to the gamer next time (even share it on facebook if it's possible ). an image...

Lua: how to check whether a process is running

I would like to start a process from Lua and monitor whether the process is still running. [EDIT] I know starting can be achieved by os:execute, but this is blocking. I would like to find a way to start a process non-blocking and monitor whether it still runs....

Redis Cluster: Find which master holds particular key/slot

I'm using Redis Cluster, and some keys have a special prefix {foo}, so redis puts them in one slot. I do this because i want to run some lua scripts against these keys (i can do this if i login to the master as a single instance). In my setup...

Reading a table when function has many argument return an error

I'm trying to read an array inside a Lua function in a library that I'm developing. When I call the function with one argument, like xyz = {3, 4, 5} setxyz(xyz) I read the array correctly, while if I add a second argument xyz = {3, 4, 5} setxyz(xyz, 3)...

Reading Lua Table from C++

I have tried many alternatives for this simple thing but could not get it work. I want user to define a table from Lua in the 1st step: a={["something"]=10} -- key=something, value=10 Then, in the second step the user will call from Lua a function designed in C++: b=afunction(a) --...

Lua - Function That Creates Detours

I need to make several detours to various functions and doing it one by one is just not an option. I'm looking for a function that will take a table, ideally, and this table is class. Loop through it and for each key, value pair that is a function make...

How I get the cdata out in c function with variable arguments using luajit?

Here is the code. The aim is to print messages. In PrintC, I would like to get e...but arrives as cdata. How can I unpack that or circumvent that? extern "C" { static int PrintC ( lua_State *L ) { // does not work cdata //executor* e = ( executor*...

Lua in-place initialized table order

I want to be able to do the following: MyObject:SetSize( { 10.0, 20.0 } ) But when I iterate over this on the C-side (SetSize is a C function). The order of the parameters is random. This is the C++ side processing the table: glm::vec2 State::PopVec2() { glm::vec2 v(); lua_pushnil(...

storyboard.removeScene(“scene name”) is not working

I am new to corona sdk and trying to build sample in it. i want to get back to main screen automatically after some time by destroying my scene(i mean that scene destroys itself after some particular time and user get back to main screen).I know that for some this...

Lua os.tempname

The file names returned by the Lua os.tempname function are weak in two respects Unlike most other languages it is not possible to define a custom prefix for the file name The _6char suffix that is generated can, with brute force but nevertheless, be guessed I have at times used...

How to iterate through a table in its exact order?

If i try to output this table, they are looped through in the false order: local letters = {DIN1="hi", AIN1= "my", AIN2 ="name", DIN2="is"} for name, value in pairs(letters) do print(name,value) end Expected Output: DIN1 hi AIN1 my AIN2 name DIN2 is Output: AIN1 my DIN2 is DIN1 hi AIN2...

2D Line reflection on a “mirror”

So I've been working at this on and off for a week, googling and all and I haven't found how to do this. I have a table of "rays" and a table of "lines", and I want the lines to act as mirrors and reflect a ray whenever the ray...

Corona sdk not view random text

I'm have a problem because when I touch my button sometimes my text doe not appear and I do not understand what is wrong. Code: function randomText(event) display.remove(mmDis) local a = {"Cristiano ronaldo jest najlepszy!", "messi jest dobry!","lewandowski jest ok","diego lopez to bramkarz realu"} com = (a[math.random(1,#a)]) local mmDis =...

Lua function selector

I have 3 functions. When the user presses the 'E' key I want it to select one of the functions (at random), I feel like it has something to do with math.random but I can't figure it out.