Most voted "lua" questions
Lua is a fast and lightweight scripting language designed to extend applications. It is typed dynamically, interpreted from bytecodes, and has automatic memory management with incremental garbage collection. Its features make Lua an ideal language for configuration, automation and rapid prototyping. (visit lua.org).
Learn more…203 questions
Sort by count of
-
4
votes3
answers702
viewsFunction that takes another function as a parameter in C#
In the language Lua has how to create a function that takes as argument another function, for example : exemplo = function(outrafunction) outrafunction() end exemplo(function print("alguma coisa")…
-
4
votes2
answers341
viewsWhat would be the correct way to verify if a value exists in the table in Lua?
if not name in Namez do table.insert(Namez,name) end What would be the correct way to check if a name is not in the table?
-
4
votes2
answers76
viewsWhy does Lua’s "print" print print extra spaces in the arguments?
I used the command print() concatenating a variable, but the output prints extra spaces. If I use the io.write(), this problem does not occur. Why this problem happens to the print()? Example: name…
-
3
votes1
answer155
viewsCheck if a value corresponds to a value in an array
How to check if a given value corresponds to another present in an array? Ex: array1 ={nome = "Fulano", idade = 15} print(array1[idade].nome)
-
3
votes1
answer197
viewsHow to link a class variable to c++ in lua script?
How do I access and set a class variable made in C++ passes to Lua? // C++ #ifndef SCRIPTSTORAGE_H #define SCRIPTSTORAGE_H #include "HTest.h" #include <luajit/lua.hpp> #include…
-
3
votes1
answer128
viewsTake array name within array
Well, what I want is the following: take the name of an array within another array, just the name. EX: local a = { ["oi"] = {sim=1, nao=2}, ["tchau"] = {sim=2, nao=1} } local falas = {}…
-
3
votes1
answer107
viewsPrint does not return table values
pokecatches = { ["Bulbasaur"] = {chance = 150, corpse = 5969}, ["Ivysaur"] = {chance = 275, corpse = 5982}, ["Venusaur"] = {chance = 400, corpse = 5962}, } print(table.maxn(pokecatches)) corpses =…
-
3
votes1
answer82
viewsString (g)Match
Well, I’m looking to turn a string into a table. I tried so: toset = "nb = 10, gb = 20, sb = 0, sfb = 0, ub = 0;" toget = "nb = (.-), gb = (.-), sb = (.-), sfb = (.-), ub = (.-);" t =…
-
3
votes1
answer196
viewsHow do you get time for a millisecond?
I would like to take the time (HH:MM:SS) per millisecond. Ex: 86400000 Would be: 24:00:00 since it is the equivalent of a day.
-
3
votes1
answer159
viewsIs it possible to detect the key pressed in Lua?
Working in terminal mode, I have control over the screen coordinates where the text will be displayed, however I need detect if a key has been pressed, without the same echo onscreen. Is there a…
-
3
votes2
answers190
viewsDelete repeated values
How could I delete repeated values in a table? Ex: a = {1,2,3,4,3,2,1} How would you delete 3, 2 and 1, keeping only one of each? My table is one inside another: a = { {a=1, b=2}, {a=2, b=3}, {a=1,…
-
3
votes1
answer1560
viewsIn Pairs or Ipairs
Is there any difference between in ipairs and in pairs? Which? a = {1, "b", 3, "d"} for i, v in pairs(a) do print(i, v) end print("Ipairs") for i, v in ipairs(a) do print(i, v) end Returns: 1 1 2 b…
luaasked 10 years, 1 month ago Gabriel Sales 1,257 -
3
votes1
answer125
views"require" in higher directories
I have a program in Lua. This is the file structure: |Programa |-Main.lua |-config.lua |--------functions |-functions.lua Through the functions.lua, I want to give a require in the config.lua. Is…
-
3
votes2
answers322
viewsGet the highest value of an array in Lua
I’m using Lua code and I want to get the higher value of an array. Example: tem_array = {10,2,3,20,1} I used this code below, but I get the number of elements and not the maximum: max =…
-
3
votes1
answer1593
viewsHow to replace certain letters of a sentence?
I want to replace these letters: local words = {"v", "s ", "#@#", "s", "รง", "b", "mp", "t"} When they had in a sentence they would be replaced, or it could be a table like this too: local words = {…
luaasked 9 years, 6 months ago Joao Gabriel 43 -
3
votes1
answer82
viewsPass this Comma Numeric function to Point
I have a function that returns the number at home of a thousand, example: function getMilharNumber(n) -- critico return…
-
3
votes3
answers905
viewsBrowse in LUA tables
I have two tables created in LUA. I want to go through if there is an equal value between the two. Something like this. table1={5,10,30,40,50,60,40} table2={10,30,40} for i=1,#table1 do if…
-
3
votes1
answer211
viewsSend mail through Lua
I want to send a simple mail in Lua, I used the example in official documentation, and always give me back nil. Example: -- load the smtp support local smtp = require("socket.smtp") from =…
-
3
votes1
answer111
viewsCreate reading of a bool function in lua
Well I’m learning moon and I’m having a doubt, I’m trying to create the reading of a bool function on moon. I have a function that disables or activates as I mark true or false. This function is…
-
3
votes1
answer232
viewsHow exactly does the Moon’s canvas.Compose() work?
canvas:Compose (x, y, canvas_src) Make pixel-by-pixel composition between two canvas. The canvas passed as src`is drawn on the canvas in use (canvas) in the past position. Receives: x: [number]…
-
3
votes1
answer854
viewsCompile using Terminal in Lua
I’m starting now the programming language studies Lua, but I’m having a hard time when I do a program in c to compile the algorithm in the terminal I write: **gcc nome-do-programa.c** and then I put…
-
3
votes1
answer75
viewsReferencing a table through a string in Lua
I need to use a table in Lua, but I can only reference it through a string, example: tabelaA = { "qualquer coisa" } variavelA = "tabelaA" print(variavelA) resultado: "qualquer coisa" Bearing in mind…
-
3
votes1
answer1144
viewsFind the angle between 2 vectors in 3d
I want the X Y Z angles between the two vectors To make a line between the two of them. math.atan2(t2.y - t1.y, t2.x - t1.x) * 180 / math.pi)-90 This is the account I used to find Z, but the others…
-
3
votes1
answer95
viewsHow do I use Hump.timer in a repeat loop in LOVE2D?
I’m asking this to make something move in LOVE2D when a key is pressed. I’ve already tried repeat imgx = imgx + 1 timer.after(0, function() end) until not love.keyboard.isDown('left') but it didn’t…
luaasked 7 years, 11 months ago arthurgps2 411 -
3
votes2
answers823
viewsHow to Manipulate UTF-8 on the Moon
How to work with a string composed of UTF-8 encoding on the Moon? For example: get a character code in a string by its index; encode character codes, something like string.char(...códigos) or…
-
3
votes2
answers3965
viewsWhat Development Environments (IDE) for Android and IOS using Lua?
I want to know what Development Environment options to develop applications for Android and IOS using the Lua language.
-
3
votes3
answers142
viewsIs there any way to get a particular line from a string?
I have this example string: s = [[Pão com Requeijão]] Is there any way to get only the second line of the string? If so, how?
-
3
votes2
answers88
viewsCan you create variables within a block and use them later?
do local a2 = 2*a local d = sqrt(b^2 - 4*a*c) x1 = (-b + d)/a2 x2 = (-b - d)/a2 end -- scope of `a2' and `d' ends here print(x1, x2) …
-
3
votes2
answers1273
viewsWhat is the difference between "in pairs" and "in ipairs" in Lua?
produtos = { arroz = 10, feijao = 15 } for produtos, valor in pairs(produtos) do print(produtos .. " custa R$" .. valor) end Returns: feijao custa R$15 arroz custa R$10 But when I use the "ipairs"…
-
3
votes2
answers93
viewsHow to print accents in Lua
I’m starting to learn moon now, and I can’t print accents print("Olá mundo") returns Ol├í mundo in both the VS Code terminal and powershell, there is a way to fix this?…
luaasked 4 years, 2 months ago Levy Barbosa 51 -
3
votes1
answer49
views"Attempt to compare string with number" when comparing in Lua
print("Qual é a sua idade") idade = io.read() if idade < 18 then print("Você é menor de idade") else print("Você é maior de idade") end He always makes that mistake : lua: aula05_parte4.lua:4:…
luaasked 3 years, 4 months ago Rogério Matheus 31 -
2
votes1
answer120
viewsHow to import Lua packages to Love?
I was observing the example files of the moon (more specifically the iup), and the dial.wlua example caught my attention a lot... I thought it would be interesting a game using this base, for time…
-
2
votes1
answer326
viewsHow to configure LUA_PATH?
I installed the IUP (Toolkit graphic) in a given folder. When I run the following script from within that folder, it works perfectly.. require("iuplua") iup.Message('Minha Aplicação','Finalizada com…
-
2
votes1
answer882
viewsLoadstring, how to use?
I’m using the loadstring function, but I don’t know if this is the right way: a= "st = {b=1, c=2}" st = {} b = loadstring(a) b() print(st.b) Is there any simpler way?…
luaasked 10 years ago Gabriel Sales 1,257 -
2
votes1
answer39
viewsGet position of wxTextCtrl
How do I get the position (x and y) of a WxTextCtrl? I didn’t find anything in the documentation.
-
2
votes2
answers162
viewsIuplua - Positioning component
In Iuplua, how do I position a component indicating the X(horizontal position) and Y(vertical position)? I read in the documentation: It will be changed During the layout computation, except when…
-
2
votes1
answer121
viewsReplace text within tag
Am I trying to replace inside a tag? EX: mystr = '<html><head></head><body><p>Aqui meu texto</p></body></html>' mystr = mystr:gsub('<.+>', '')…
luaasked 9 years, 10 months ago Gabriel Sales 1,257 -
2
votes1
answer125
viewsRead LUA file
I have a file that I just want to read some lines, not all lines. I get the lines I want to read, which are numbers. I can only read the entire file. local inicio = GET["inicio"] local fim =…
-
2
votes1
answer463
viewsRun Lua code block inside C++
How do I run a Lua code block inside a C function++? The idea would be something like: int main() { tipodavariavel script; script << "print('Ola mundo')"; executar(script); return 0; }…
-
2
votes1
answer257
viewsCalculate x in x seconds
I have this code that calculates in 1 second in 1 second between a certain time and then insert into a table. Instead of calculating every 1 second, how can I calculate, for example, every 5…
-
2
votes1
answer190
viewsRead table in Lua through C++
I have a table in Lua this way: myTable={ one = {a=1, b=2, c=3}, two = {a=4, b=2, c=1} } The file has already been uploaded, as I do to read the table data through C++?…
-
2
votes1
answer138
viewsPHP implode on LUA
I have the following code that passes a php array to JS: var js_array_date1 = [<?php echo '"'.implode('","', $newarray_date1).'"' ?>]; My problem is how I can do this in LUA. Pass a LUA array…
-
2
votes1
answer145
viewsCheck the URL for a variable passed GET LUA
I want to check through the URL if I have any variables passed to via GET. For example at this url: www.exemplo.htm?teste=teste if url then -- se na barra de endereço tem um get return true else…
-
2
votes1
answer131
viewsSend e-mail with attachment in Lua
I’m trying to send an e-mail behind the socket. I can send an email with an attachment, but I also want to add text to the email and I can’t. Example of the code: local smtp = require("socket.smtp")…
-
2
votes1
answer129
viewsHow to get only a part of a string from a pattern?
I have a string in Lua language. I want to get only the part of filename through the match (403.htm.en). Example: var=[[Content-Disposition: attachment; filename="403.htm.en" Content-Type:…
-
2
votes1
answer130
viewsGet part of a string
I am going to fetch some data from a file in ics format. The problem is that the file can change several times. I have this code to put in each variable each data of a certain line in the file.…
-
2
votes1
answer2162
viewsShow a specific number of decimals in floating point numbers in Lua language
I started to learn a little about the language Lua and I’m doing some algorithms to practice and one of them I should show in the output of floating point values with 4 decimal places. In C++ I…
-
2
votes0
answers172
viewshow the moon (Corona sdk) runs on android
I’m testing the sdk Corona for android, and I’m finding it very good. Of course they are simple tests, but ran very well on an old phone with android 2.3, and the same apk ran on android 6. Both the…
-
2
votes0
answers39
viewsMoon randomseed function only within a body (do)
I’ve been programming Lua for a long time, but I’ve almost never had to work with math.randomseed, I searched and found nothing informing about it, did some testing and none worked as I expected.…
-
2
votes0
answers73
viewstable change to your call in . moon?
have this table below tabela = { ["Maquina"] = { {name = "susu", level = 600}, {name = "camel", level = 600}, {name = "juju", level = 600}, }, ["bruno"] = { {name = "fada", level = 600}, {name =…