Ok, I think I overcomplicated things and now I'm lost. Basically, I need to translate this, from Perl to Lua:
my $mem;
my $memfree;
open(FILE, 'proc/meminfo');
while (<FILE>)
{
if (m/MemTotal/)
{
$mem = $_;
$mem =~ s/.*:(.*)/$1/;
}
}
close(FILE);
So far I've written this:
for Line in io.lines("/proc/memin...
Hi,
I am trying to load the example lproc program (described on Programming Lua, Chapter 30) into Lua and fouling up somehow. I am following this - http://www.lua.org/pil/26.2.html to get my c module into lua. Following are the steps that I've taken:
I have an lproc.h and lproc.c (containing exactly the functions laid out in Chapter 3...
I've implemented my own class system and I'm having trouble with __tostring; I suspect a similar issue can happen with other metamethods, but I haven't tried.
(Brief detour: each class has a __classDict attribute, holding all methods. It is used as the class instances' __index. At the same time, the __classDict's __index is the supercla...
Whenever an error occurs in a Lua script, I'd like it to write the values of all local and global variables to the screen/optionally to a file - in addition to the usual stack trace.
How could I get this to be the default behavior for all errors?
...
I've never been able to fully wrap my mind about how Lua uses metatables to implement Object Orientation in its programming. I've been reading over the online tutorial directory trying to understand, however the author wrote it with experienced programmers in mind, in which I am not. With abstract ideas and not-noob-friendly variables an...
Hey, I'm trying to implement the merge function from merge sort in Lua. I know the algorithm pretty well, but I'm new to Lua. I keep getting a "bad argument #1 to 'insert' (table expected, got nil)" I believe the error is pointing at my recursive call. I can't figure it out and I have a feeling it's something pretty trivial. I just n...
Is there a Lua library (or with Lua bindings) to build graphs (directed/undirected), with traversal algorithms, connectivity tests, and other basic graph operations?
...
I'm confronted with the task of making a C++ app scriptable by users. The app has been in development for several years with no one wasting a thought on this before. It contains all sorts of niceties like multithreading, template wizardry and multiple inheritance. As the scripting language, Python is preferred, but Lua might be accepted ...
What's the proper pattern to close all open cursors in a lua script before closing the db connection? I have a helper function rows() that is called in multiple places which creates cursors, on the function end() I want to be able to close all that have been created.
function rows (sql_statement)
local cursor = assert (con:execute (s...
I'm learning how to bind C++ objects to Lua with type checking from the book Programming Gems 6 (Chapter 4.2). For the type checking the userdata/string pairs are being stored in an environment table, with the code given how to do that:
void Binder::pushusertype(void* udata, const char* tname) {
lua_pushlightuserdata(L, udata); // push...
I see many text editors for Mac OS X that support Lua syntax highlighting, but I have yet to see an example of Lua being used in action in the actual Operating System.
How is Lua being used practically?
...
I've been developing a highly modified version of Lua (including a rewrite of the sources to keep a better maintainability). Right now i'm at a point where I would consider forking Lua, and possibly re-release it under a different name (so people don't mistake it as the original Lua interpreter).
Of course the resulting Interpreter and ...
In Lua, you can create a table whose keys are themselves tables:
t = {}
t[{1,2}] = 2
I would like to know how to do the analogous thing using the C API. That is, I am writing a C function callable from Lua, which will return a table with table keys. I tried to push a table as a key and then use lua_settable, but it seems to do nothing...
I have some classes in C++ that I would like to expose to Lua. I can call Widget:New() to get return userdata with a metatable set to the table WidgetMeta. WidgetMeta has all the C++ functions in it, and it's __index is set to itself, so I can do this:
w = Widget:New()
w:Foo() -- Foo is defined in C code
That's all pretty straightforw...
I've heard that you can tilt a part by a precise amount using the .CFrame property. However, I'm unclear on how to use it. The following code does not work:
Workspace.Part.CFrame = CFrame.new(90,0,45)
It is not rotating the part by 90 degrees and 45 degrees. What am I doing wrong?
...
Is there a compiler for Lua that compiles to JVM bytecode (and would thus be able to run on Google app engine)?
...
Hello,
Today I've tried to get Edit & Continue to work in my solution, which looks like this:
Game Engine .lib <- Game .lib <- Editor .exe
<- Server .exe
<- Client .exe
Which works nicely. But now I wanted to turn the engine and game .libs into .dlls, so I can use the Edit & Continue ...
luaL_loadfile(mState, path.c_str());
lua_pcall(mState, 0, 0, 0);
Is there a way to put an execution time limit (say 10-20 seconds) for those two C++ statements, that load and then execute a lua file?
Since the Lua file is untrusted I don't want a malicious user to hang the program indefinitely with an infinite loop in the Lua code.
T...
I've been trying to integrate Lua into my managed code, using LuaInterface. I'm using the lua51.dll that came with the assembly I downloaded, but when I try to create a new Lua object, the constructor fails with ERROR_DLL_INIT_FAILED, or HRESULT 0x8007045A. I checked that I'm building as x86. What else can be the problem?
...
I have a function that takes a variable number of arguments in C that I want to pass to another lua function. In pure Lua I could do something like this
function foo(...)
print(...)
end
How would I do the same thing if I were to implement the function in C?
Edit: I might have worded this poorly. What I want to do is write the fun...