lua

How do I get the number of keys in a hash table in Lua?

myTable = {} myTable["foo"] = 12 myTable["bar"] = "blah" print(#myTable) -- this prints 0 Do I actually have to iterate through the items in the table to get the number of keys? numItems = 0 for k,v in pairs(myTable) do numItems = numItems + 1 end print(numItems) -- this prints 2 ...

Search for an item in a Lua list

If I have a list of items like this: local items = { "apple", "orange", "pear", "banana" } how do I check if "orange" is in this list? In Python I could do: if "orange" in items: # do something Is there an equivalent in Lua? ...

Are curly brackets used in Lua?

If curly brackets ('{' and '}') are used in Lua, what are they used for? ...

Anyone got LunarEclipse to work with Eclipse 3.4.1?

I spent a couple of hours yesterday trying to get LunarEclipse to work with Eclipse 3.4.1 and DLTK 1.0 I looked at some bug reports at their sourceforge project page and they said that their 1.2.9 version was supposed to work with DLTK1.0. Problem being they hadn't actually released the 1.2.9 yet. You could get it at their SVN repositor...

How to load all files from a directory?

Like the title says; how do I load every file in a directory? I'm interested in both c++ and lua. Edit: For windows I'd be glad for some real working code and especially for lua. I can do with boost::filesystem for c++. ...

Lua registry not visible from new states

In a C function called from my Lua script, I'm using luaL_ref to store a reference to a function. However, if I then try to use the returned integer index to fetch that function from a different thread which isn't derived from the same state, all I get back is nil. Here's the simplest example that seems to demonstrate it: // Assumes a v...

Query Lua userdata type from C

I have a Lua userdata object with a certain metatable type (e.g. "stackoverflow.test"). From C code, I want to be able to check exactly which type it is, and behave differently depending on the results. Is there a nice handy function (rather like luaL_checkudata, but without erroring if the answer isn't what you want) that let's me query...

What's with PCALL or is Wowwiki wrong?

This is a WoW (World of Warcraft) lua script question. Not many of these get asked here but I have no where to turn and Stackoverflow is the programmer oasis for answers. Question: Wowwiki states that the 2nd, 3rd, 4th arguments are your calling functions 1st, 2nd, 3rd arguments. I don't find this to be true. I find that the 3rd, 4th, ...

Best tool(s) for decompiling Lua bytecode?

I am really having trouble finding a good working Lua bytecode decompiler. I'm trying to decompile some scripting files I found in a game but they appear to be compiled, yet don't seem impossible to decode. What's the best tool to decompile Lua binaries? ...

Debugging embedded Lua

How do you debug lua code embedded in a c++ application? From what I gather, either I need to buy a special IDE and link in their special lua runtime (ugh). Or I need to build a debug console in to the game engine, using the lua debug API calls. I am leaning toward writing my own debug console, but it seems like a lot of work. Time th...

Is there any way to programmatically determine in C/C++ how many parameters a Lua function expects?

Is there a way to determine how many parameters a Lua function takes just before calling it from C/C++ code? I looked at lua_Debug and lua_getinfo but they don't appear to provide what I need. It may seem a bit like I am going against the spirit of Lua but I really want to bullet proof the interface that I have between Lua and C++. Wh...

A function expects a C++ object of abstract type A. How do I pass it a Lua object of an A subclass?

I'd like to pass to a function expecting a C++ object of a pure virtual class a Lua object of a class that derives from the pure virtual C++ class. How can I do this? I'm new to lua and luabind so bear with me. In C++: struct A { virtual void foo() = 0; }; void do_something(A* a) { a->foo(); } In Lua: class 'MyA' (A) .... func...

Strongly typed Lua

I am looking for a Lua front-end compiler that is strongly-type, but outputs standard Lua 5.1 byte-code (that has no notion of types at all). What I want is a decent amount of static, compile-time syntactic analysis and optional typing, to detect trivial errors sooner than run-time. The resulting byte-code would have to play nicely wit...

Getting input with IUP in Lua

I've been trying to get input with IUP to make a small pong game. I wanted to try some input, and tried some of the code that comes with the IUPGL examples, but the input doesn't seem to be working at all. Here's the code as it stands so far: require "iuplua" require "iupluagl" require "luagl" paddle = {x = -0.9, y = 0.2} function d...

how to iterate individual characters in Lua string?

I have a string in Lua and want to iterate individual characters in it. But none code i have tried is working and official manual only shows how to find and replace substrings :( str = "abcd" for char in str do -- error print( char ) end for i = 1, str:len() do print( str[ i ] ) -- nil end ...

Asynchronous input in Lua

In a related question I asked how to get input via IUP. This works fine, except that it goes through the system, and is subject to the repreat rate which is not optimal for a game. What I would really like is the ability to obtain the current state of any key at a given time. Is there a way to do this (through IUP or otherwise)? ...

Controlling Lua5.1's garbage collector

OK so I have a C++ class that is exposed to Lua using SWIG. The script creates the object but a manager class also has a pointer to the object so it can be modified in C++(or another script) for whatever reason. The problem is that when the script finishes the object is freed, how can I control what the Garbage collector collects withou...

How do I pass a list of objects from C++ to Lua?

I'm the lead dev for Bitfighter, and am adding user-scripted bots using Lua. I'm working with C++ and Lua using Lunar to glue them together. I'm trying to do something that I think should be pretty simple: I have an C++ object in Lua (bot in the code below), and I call a method on it that (findItems) which causes C++ to search the area...

Tweening a value in Lua

How'd I go about this one? I want to tween a value from one to another in x time. While also taking into account that it'd be nice to have an 'ease' at the start and end. I know, I shouldn't ask really, but I've tried myself, and I'm stuck. Please assume that to cause a delay, you need to call function wait(time). ...

How can I end a Lua thread cleanly?

My situation is that I'm using the Lua (C) API to execute a script held in a string. I would like the user to be able to terminate the execution of the script (this is essential if the script contains an infinite loop), how can I do this? lua_State *Lua = lua_open(); char * code; // Initialisation code luaL_dostring(L, code); ...