In Lua, you can create a table the following way :
local t = { 1, 2, 3, 4, 5 }
However, I want to create an associative table, I have to do it the following way :
local t = {}
t['foo'] = 1
t['bar'] = 2
The following gives an error :
local t = { 'foo' = 1, 'bar' = 2 }
Is there a way to do it similarly to my first code snippet ?
...
how do you make a default table and then use it when making other tables?
example
--default table
Button = {
x = 0,
y = 0,
w = 10,
h = 10,
Texture = "buttonimg.png",
onClick = function() end
}
newbutton = Button {
onClick = function()
print("button 1 pressed")
end
}
newbutton2 = Button {
x = 12,
onClick = function()
pr...
Is there any Lua power user wishing to share a gem of hidden knowledge about this nice language? Any trick that can be useful is welcome, be it for extending C/C++ applications or extending the Lua language.
...
Calling a Lua function from C is fairly straight forward but is there a way to store a Lua function somewhere for later use? I want to store user defined Lua functions passed to my C function for use on events, similar to how the Connect function works in wxLua.
...
Currently I have a set of SWIG wrappers for my classes and it all builds. I can create a lua virtual machine and load my wrappers, but at that point I'm flummoxed. Googling tells me how to shove put c++ in lua in swig, but not how to put lua in c++.
Really all I want to do is manage to instantiate a lua object and pass it my main game e...
I currently have the following lua code:
g = engine.CGeometry()
vertexes = {}
vertexes[1] = 0
vertexes[2] = 0
vertexes[3] = 0
vertexes[4] = 0
vertexes[5] = -1
vertexes[6] = 0
vertexes[7] = -1
vertexes[8] = 0
vertexes[9] = 0
print "adding vertexes"
g:SetVertexes(vertexes)
where g...
There are some very good books about Lua. What they cannot cover is the big picture, when it comes to real applications (doc/view-type of applications). The interesting things are around those questions:
Use C++ in Lua or Lua in C++?
Who gets the main-loop?
What plays where?
How are model (document) and Lua-State kept in sync? Should t...
I use very simple Lua scripting in an online game called ROBLOX. My problem is that values in my scripts aren't changing! Example:
num = 0
while true do
num = num + 1
print(num)
wait(1)
end
That should count up starting on 0, but the number won't change. Could this be from the ROBLOX website? I can't figure out what else it might be.
...
Hi, how do I check the value of the top of the stack in Lua?
I have the following C++ code:
if (luaL_loadfile(L, filename) == NULL) {
return 0;// error..
}
lua_pcall(L,0,0,0); // execute the current script..
lua_getglobal(L,"variable");
if (!lua_isstring(L,-1)){ // fails this check..
lua_pop(L,1);
retu...
I'm trying to write a lua script that reads input from other processes and analyzes it. For this purpose I'm using io.popen and it works as expected in Windows, but on Unix(Solaris) reading from io.popen blocks, so the script just waits there until something comes along instead of returning immediately...
As far as I know I can't change...
I am interested in hearing about peoples experience with embedding mono (open source implementation of .NET) in a C/C++ application. How is it to distribute such an application and what are the dependencies? I have tested on OS X and mono comes as a huge framework (hundreds of MB). Do users of my app all need this big framework or can it...
The only thing I know about Lua is that it is used to develop Ion (which is a tiling tabbed window manager designed with keyboard users in mind.)
Since I'm on SO, I can see some question about Lua, about 80 question with this tag, so I was wondering if someone could tell me briefly what this language is about and what are the advantages...
Lua is currently the fastest scripting language out there, and its not so much slower than C/C++ for some sort of programs (on par when doing pidgits 1:1), however Lua scores really bad in a few benchmarks against C/C++.
One of those is the fannkuch test (Indexed-access to tiny integer-sequence), where it scores a horrible 1:148
-- The...
Status: So far the best answer's program executes in 33% of the time of the original program! But there is probably still other ways to optimize it.
Lua is currently the fastest scripting language out there, however Lua scores really bad in a few benchmarks against C/C++.
One of those is the mandelbrot test (Generate Mandelbrot set p...
Lua is currently the fastest scripting language out there, and its not so much slower than C/C++ for some sort of programs (on par when doing pidgits 1:1), however Lua scores really bad in a few benchmarks against C/C++.
One of those is the spectral-norm test (Eigenvalue using the power method N=5,500 ), where it scores a horrible 1:148...
I'm at a stage where I am forced to learn Lua, so do you have any suggestions on how I do this? I don't have a lot of experience with any other scripting languages than PHP.
So, some suggestions on "head start lua"-pages?
EDIT
As an addition to the wonderful tutorial pages, could you plaese suggest any "programs" I could make that wil...
Hi,
I'm playing WoW for about 2 years and I was quite curious about Lua which is used to write addons. Since what I've read so far about Lua was "fast", "light" and "this is great", I was wondering how and when to use it.
What is the typical situation where you will need to embed a script language like Lua in a system ?
...
I have a class that is wrapped with swig, and registered with lua. I can create an instance of this class in a lua script, and it all works fine.
But say I have an instance of a class made in my c++ code with a call to new X, and I have la lua_state L with a function in it that I want to call, which accepts one argument, an instance of ...
Recently I wrote a bit of Lua code something like:
local a = {}
for i = 1, n do
local copy = a
-- alter the values in the copy
end
Obviously, that wasn't what I wanted to do since variables hold references to an anonymous table not the values of the table themselves in Lua. This is clearly laid out in Programming in Lua, but I'...
Is there a way to run Lua code from a C/C++ program at a more fine-grained level than a standard "lua_pcall" function call? Ideally I'd like to be able to loop over a list of low-level bytecode instructions (assuming it has such things) and run them one by one, so that I could write my own scheduler which had more control of things than ...