How to use to read a number

I'm a Lua beginner and don't know how to properly use and such. I'm working on something very simple and I wanted to replace the age = 18 statement to something that can get the input from the user, asking them to say their age. Instead of th

Why L- & gt; l_G- & gt; _defaultmeta.value.gc is still NULL?

I am currently trying to hack the Lua implementation of a game in order to extend the built-in methods for game modders. In order to do so, I try to hijack a the pointer to a valid lua_State struct and register new libraries with it. I have now tried

Lua 5.3 - Integers - type () - lua_type ()

Since Lua 5.3, inegers are supported. But how can I do : if type( 123 ) == "integer" then end Or switch( lua_type( L, -1 ) ) { case LUA_TINTEGER: break; } Since type() is still going to return "number" for both integer and reals, and L

Difference between math.random () and math.randomseed () in Lua

I am working on game using Corona SDK with Lua as Programming Language . While getting random number from table , I am confused to use which one of following ? math.random() math.randomseed() Will any one elaborate the exact difference between them ?

View a simple message box in Lua

It sounds like a "let me google it for you" type of a question, but after some substantial amount of research, I couldn't find the answer. Is there a built-in message box method in Lua? If not, what is the "standard" way of doing that?

What is the problem with the function overwritten in lua?

function f() return 1 end function f(N) if N == 42 then return f() else return 2 end end f is overwritten, but f(42) returns 2 instead of 1. Why? Is this possible?You can't overload a function in Lua. You can just "redefine" it. So : function f(

Why is the car zero? How would I do that?

t = {} a = function() print(self) end t.a = a t:a() I don't want to pass in self, I want to use the syntactic sugar.function foo:bar() ... end silently inserts a parameter called self as the first argument, making it equivalent to function

The Magic Square algorithm

As an experiment, I'm trying to create a magic square program that checks every possible square with nine numbers. For those who do not know, a magic square is a 3x3 grid of numbers 1-9, where each row, column, and diagonal add up to 15. For example:

Creating a Recursive LPeg Template

In a normal PEG (parsing expression grammar) this is a valid grammar: values <- number (comma values)* number <- [0-9]+ comma <- ',' However, if I try to write this using LPeg the recursive nature of that rule fails: local lpeg = require'lpeg' lo

Differences between two tables in Lua

I have two tables in lua (In production, a has 18 elements and b has 8): local a = {1,2,3,4,5,6} local b = {3,5,7,8,9} I need to return 'a' omitting any common elements from 'b' -- {1,2,4,6} similar to the ruby command a-b (if a and b were arrays). T

How to convert a string to a table in Lua

I am having a table data in string form. Sample is given below: {"engName1":"HOLDER","validDurPeriod":3,"engName2":"INFORMATION","appStatus":2,"stayExpDate":"01/10/2012","

Several hashes inside a hash in lua

I wanted to know if the functionality i am trying to implement in lua is possible. I have a global hash called Creatures. Creatures contain sub-hashes called mammals, amphibians, birds, insects. Mammals have sub-hashes called whales, elephants. Amphi

incorporation luajit undefined reference

I'm unsuccessfully trying to embed (statically) luajit into a c++ application. I have followed the steps from the luajit site to no avail, googled on the subject and got no relevant information and tried every thing I could think of. It appears as if

How to get the IP address of the client in Lua Sockets

I'm having trouble locating how I go about getting the ip address of each client as they connect to my server, using LuaSockets; Also: I apologise if this has been answered in another post, but I could find it; Link me if this is the case. Cheers!get

LuaJIT does not see the rocks installed by LuaRocks

lua -e "print(package.path)" ./?.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/usr/lib/lua/5.1/?.lua;/usr/lib/lua/5.1/?/init.lua luajit -e "print(package.path)" ./?.lua;/usr/local/share/luajit-2.0.0-beta8/?.lua;/usr/local

Lua returns from the problem of the function

I'm trying to parse some xml files with lua and I'm stuck on this function: function get_node_by_id (xml, nodeId) for i=1, #xml, 1 do if get_attr_by_name(xml[i], 'Id') == nodeId then print ("TRUEEEEE", i, xml[i]) return xml[i] else get_node_by_i

What is a good game engine that uses Lua?

I know Love2D and Corona SDK (for mobile devices). Is there any other game engines that use Lua you recommend?Game engines that use Lua Free unless noted Agen (2D Lua; Windows) Amulet (2D Lua; Window, Linux, Mac, HTML5, iOS) Baja Engine (3D C++/Lua;

Memory leaks - the horror of every programmer?

I'm programming a game engine in C++, which also has Lua support. My biggest horror: Memory leaks. It's not like my game is already infested with them, I'm rather afraid of them popping out of the ground like mushrooms, when the development is in a l

Teach children to debug the code?

So there are a lot of posts around here about what are the best ways to teach kids to program. I'm interested in the next step, teaching kids how to debug code that doesn't do what they want, or doesn't always work 100% of the time (I believe these a

Lua interpreter on Iphone

Is it possible to run Lua interpreter on the iphone? If yes, are there any libraries that have bindings to Iphone's SDK? If its not possible with Lua, what are the other language options?See the Ansca Corona SDK.

How to call C ++ functions from a Lua script?

I'm using Visual Studio 2005. ------------------------[ luapassing.cpp ]-------------------- #include "lua.h" static int myCfunc (Lua_State *L){ double trouble = lua_tonumber(L,1); lua_pushnumber(L,16.0 -trouble); return 1; } int luaopen_luapass

how to get the closure in Lua?

suppose i have a file name "test.lua" containing lines below: --[[ test.lua --]] local f = function() print"local function f in test.lua" end f_generate = function() local fun = loadstring(" f()") -- local env = getfenv(1) --