spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » LUA » Page 1
Lua pattern help (Double parentheses)
You're friend is thinking of regular expressions. Lua patterns are similar, but different. % is the correct escape character. Your pattern should be %(%(.-%)%). The - is similar to * in that it matches any number of the preceding sequence, but while * tries to match as many characters as it can (it's greedy), - matches the least amount of characters possible (it's non-greedy). It won't go overboa

Categories : Lua

how to stop objects from being dragged off screen
What you could do is make the monkey a dynamic physics body, and then put essential for static walls on the outside of the screen. This should theoretically prevent the user from dragging the monkey outside of a given space. Another way you might me able to do that is to have a runtime event check if the monkey is outside of a current area, to move them to a different area. For example: functi

Categories : Lua

Point table to another table in Lua
You want the __index metamethod: local a = { name="Josh" } local b = {} print(a.name) --> Josh print(b.name) --> nil setmetatable(b,{__index=a}) print(b.name) --> Josh a.name = "Gilligan" print(a.name) --> Gilligan print(b.name) --> Gilligan -- but note! the shadow b.name = "overridden" print(a.name) --> Gilligan print(b.name) --> overridden b.name = nil print(a.name) --

Categories : Lua

Combine few arrays into one array in Lua - arg.n error
Your code works in older version of Lua. In Lua 5.2, arg isn't used to process variadic functions any more. Instead, it's a global variable that stores the command line arguments. To process variadic functions, use ... like this: function foo(...) for k, v in ipairs{...} do --process end end The n field isn't used to get table length any more, either. Use #t to get the length of a se

Categories : Lua

What is the syntax code for usleep in Lua?
http://lua-users.org/wiki/SleepFunction http://linux.die.net/man/3/usleep And here an example: http://www.troubleshooters.com/codecorn/lua/lua_lua_calls_c.htm#_Make_an_msleep_Function usleep(x)

Categories : Lua

while constantly moving character, it skips frames
You should cancel the previous transition before starting a new one (on same parameters). Do this by saving the return value of transition.to and checking, before creating new transition, whether the variable is defined, if yes then call transition.cancel() on it: local trans = nil local function moveMonkey(event) if event.phase == "began" then speed = 1500 / screenWidth * (mAbs(

Categories : Lua

Loading images from another LUA file - corona sdk
Can you give us complete code? the problem probably is that playerGroup is getting destroyed when you are switching from main to game.lua You can create it without any parent and it will remain until you manually remove it

Categories : Lua

How to get past 1gb memory limit of 64 bit LuaJIT on Linux?
Only object allocated by LuaJIT itself are limited to the first 2GB of memory. This means that tables, strings, full userdata (i.e. not lightuserdata), and FFI objects allocated with ffi.new will count towards the limit, but objects allocated with malloc, mmap, etc. are not subjected to this limit (regardless if called by a C module or the FFI). An example for allocating a structure with malloc:

Categories : Lua

How to do lookahead properly with LPeg
You need to negate "cat" at each position in the lookahead that can match: local patt2 = lpeg.C(lpeg.P"dog" * (lpeg.P(1)-lpeg.P"cat") ^ 1) * #lpeg.P"cat" I think it's appropriate to plug the debugger I've been working on (pegdebug), as it helps in cases like this. Here is the output it generates for the original lpeg-expression: + Exp 1 "d" + Dog 1 "d" = Dog 1-3 "dog" + Separator

Categories : Lua

How to redirect stdout to file in Lua?
You need to use io.write method instead of print. It works in a similar way, but doesn't separate parameters with a tab. io.write respects io.output, but print doesn't.

Categories : Lua

How to capture & pattern match for long command line args in Lua?
You aren't forcing the match to happen at the start of your argument so it is happily skipping a leading - and matching the rest of the argument. Small modification to your script to run stand-alone and to capture where the match starts: for i = 1, #arg, 1 do print("arg[i]=", arg[i]) local string = arg[i] local p,k,v = string:match("()%-%-([^=-]+)=([^=]+)") print("p=", p) pri

Categories : Lua


Recently Add
Dynamically created variables in for loop
Lua pattern help (Double parentheses)
how to stop objects from being dragged off screen
Point table to another table in Lua
Combine few arrays into one array in Lua - arg.n error
What is the syntax code for usleep in Lua?
while constantly moving character, it skips frames
Loading images from another LUA file - corona sdk
How to get past 1gb memory limit of 64 bit LuaJIT on Linux?
How to do lookahead properly with LPeg
How to redirect stdout to file in Lua?
How to capture & pattern match for long command line args in Lua?
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.