1,441 questions
0
votes
0
answers
147
views
How do I create larger structs using tables in lua? (in the pico-8 game engine)
I am making a card game and im now revamping how individual card information is stored.
a single card would have the following values:
x, y, suit, number, state
this is to be stored in a deck array ...
2
votes
3
answers
106
views
Why do these Lua array initialization constructs have differing semantics?
As I understand Lua, an array is just a table where the keys start at 1 and increment sequentially. However, there are features within Lua to manipulate arrays in the traditional sense (e.g. ipairs, ...
0
votes
2
answers
84
views
Change brick color repeatedly
I'm trying to make a dance floor that lights up and changes colors periodically. So far I've gotten the game to load and pick a random color from the array upon loading, but I can't make the tiles ...
-1
votes
1
answer
78
views
How to block functions from being overwritten?
I program in Lua and I need some help:
I have file1.lua and file2.lua
In file1.lua:
loadstring('print("Hello World!")')
in file2.lua:
_loadstring = loadstring
function loadstring(code)
...
3
votes
1
answer
80
views
table.insert not replacing the first nil position in the table
I started learning Lua recently, as far as I can tell, when I don't specify the index, the function table.insert tries to put the value in the first nil in the table.
Why then is it that in table t ...
1
vote
1
answer
100
views
Lua equivalent for null conditional operator? [duplicate]
In lua, if we try to index a series of nested table (any of which can be nil), we might write code like this:
-- try to get a.b.c
local ret
if a then
local b = a.b
if b then
ret = b.c
...
2
votes
1
answer
30
views
Value not changing between tables
Here's code for a timer:
local copyTable = require("Helpers.copyTable")
local timer = {}
timer.max = 0
timer.time = 0
function timer:add(dt)
timer.time = timer.time + dt
end
function ...
1
vote
1
answer
80
views
Getting the key a value was assigned to in a table in lua
So I'm trying to make a table of all the creatures in a game, each creature consisting of a table with their stats. I used the creature's name as the key in the first table, but now I need to get that ...
0
votes
1
answer
82
views
How can I parse a LuaTable in C#?
I am at a complete loss with the syntax to parse a LuaTable. I have a table that follows the following structure:
mission =
{
["coalition"] =
{
["blue"] =
...
1
vote
1
answer
64
views
Performance of calling a function, passing multiple return values from another function call?
A function f() returns multiple values, which are to be fed into a second function g(). I cannot change f(), but I can change g() and all calls to it. I'm wondering if it's possible to say which ...
2
votes
0
answers
101
views
Can I change the default hash function?
I is possible to change the default hash function that lua (or luajit) uses for the HashTable part of a talbe ?
I want to speedup table access in pure Lua.
I saw that:
The Default hash function for ...
4
votes
2
answers
446
views
Is there a way to use <const> inside a Lua table?
Since Lua 5.4, the <const> syntax lets us set const variables. I noticed that this doesn't transitively affect fields inside a table.
local x <const> = {
a = {1,2,3},
b = {5,6,7}
}
...
2
votes
1
answer
171
views
How can I convert a String that is formatted like a table, into a table?
I did find a version of this for a string into a table that splits up the letters of the string, but I have a table, that I turn into a string to remove the first part of it, and now I want it back as ...
1
vote
1
answer
75
views
Dual representation and proxies to achieve privacy in Lua
I am reading Programming in Lua, 4th edition with an intention to solve every exercise in that book. The last exercise in Chapter 21 p. 172 is the following (emphs are mine):
A variation of the dual ...
2
votes
3
answers
2k
views
Lua: is there a need to use hash of string as a key in lua tables
I want to keep a list of words (let's say 20k). The only purpose of it is to check if the given word exists there. So, it's going be something known as a hash set.
-- dict here is just an example, it'...
-1
votes
1
answer
100
views
How to make table from io.read in lua
I want to make a Table in lua with io.read, This is my code:
local members = {}
io.write("How many members you wanna add? ")
local memberNum = io.read("n")
print("Add new ...
2
votes
1
answer
76
views
Lua table created in C returns strange values for integers
I want to create a nested table, that shall look like this:
{
SA_1: {1,2,3,4},
SA_2: {11,22,33,44}
}
The code I have (I changed the SA_2 to strings for testing purposes):
int myRegisteredCfunc:
{
...
0
votes
1
answer
333
views
How to get the position of a moving object once? without it being updated
I have an object moving "freely" with body:applyForce( x, y ).
I want to track it's previous position.
I set a timer and with every second that goes by i get the position of the moving ...
0
votes
0
answers
104
views
Lua: Handle dynamic nested table (get and set)
I have a table t which is totally dynamic: it is nested, and number of levels is unknown in advance. I wish to be able to set (get is easy to do) some value at some level, using a kind of path. The ...
0
votes
0
answers
22
views
Pulling GroupId from moduleScript
I'm working on a Roblox overhead GUI and I'm using a moduleScript for the values. It currently pulls a random value of its liking instead of abiding to the parameters.
The (relevant) part of the ...
0
votes
1
answer
101
views
Lua sorting a table twice by different fields
Below is a sample table structure of what I am wanting to sort.
Data = {
["C1_RN1::F1"] = {
["class"] = "Hunter",
["name"] = "C1",...
2
votes
1
answer
72
views
How to check in Lua if there are multiple elements in a table?
I made a program, which checks if in table has (for example) "A" and a "B" in itself. But it doesn't works.
Here's code:
function inTable(t,e)
return t[e] ~= nil
end
--Example
...
0
votes
0
answers
105
views
How to add an empty table to an existing table in Lua using its C-API?
The core detail of my problem is: I don't know how to do it.
I encountered the problem I'm trying to solve by wanting to add a table to an existing table in Lua.
The major difficulty that prevented me ...
0
votes
1
answer
354
views
How do I find the index of an element in a table in Lua? [duplicate]
Let's say I have this code:
local testtbl = {"foo", "bar", "baz"}
How do I get the index of an element?
For example:
print(indexOf(testtbl, "bar")) -- 2
1
vote
1
answer
117
views
Read both key and values of a nested lua script in C/C++
I've the following lua script, in which I use a C++ function that needs to read both keys and values of a nested table:
local scenariolist = {
scenarios = {
'scenario1',
'scenario3',
...