lua

how do I clean up my lua state stack?

I am using the lua C-API to read in configuration data that is stored in a lua file. I've got a nice little table in the file and I've written a query C-function that parses out a specific field in the table. (yay it works!) It works by calling a few of these kinds of functions over and over: ... lua_getglobal (...); lua_pushintege...

How can I write a function that returns a list of keys in a nested table?

I have a hierarchically nested associative array. It looks like this: A = { B = { C = {}, D = {}, }, E = { F = { G = {} } }, H = {} } I would like to write a function that returns the "ancestors" of each key. So: f("A") = {"A"} f("B") = {"B","A"} f("C") =...

Upload a photo to facebook using Corona?

Is is possible to upload a photo to facebook using Corona? ...

Best datastructure for a heightmap

I have a heightmap (a 2D array of floating point values) and I wish to find the highest point on the map, once I have found this point, I want to change its value, and the values of all nearby points. What's the best datastructure to use for efficient retrieval of the highest point? Requirements: Find the highest point efficiently Cha...

Windows game: UTF-8, UTF-16, DirectX and Lua

I'm developing a game for windows for learning purposes (I'm learning DirectX). I would like it to have UTF support. Reading this question I learned that windows uses wchar_t, which is UTF-16. I want my game to have Lua scripting support, and Lua doesn't really like Unicode much.. It simply treats strings as a "stream of bytes"; this wo...

Calling Lua function without executing script

I am embedding Lua into a C/C++ application. Is there any way to call a Lua function from C/C++ without executing the entire script first? I've tried doing this: //call lua script from C/C++ program luaL_loadfile(L,"hello.lua"); //call lua function from C/C++ program lua_getglobal(L,"bar"); lua_call(L,0,0); But it gives me this: ...

How can a script retain its values through different script loading in Lua?

My current problem is that I have several enemies share the same A.I. script, and one other object that does something different. The function in the script is called AILogic. I want these enemies to move independently, but this is proving to be an issue. Here is what I've tried. 1) Calling dofile in the enemy's constructor, and then ca...

How to use code generation to dynamically create C# methods?

In order to define a method in C that is callable by Lua it has to match a given signature and use the Lua API to retrieve parameters and return results. I'm writing a C# wrapper of Lua and I'm interested in being able to call arbitrary C# methods without making them follow these conventions. When wrapping in something like D, one might ...

How do I use Luabind and C++ to create an asset managing class?

I've made countless attempts to get this working, but everything I do gives me run-time errors. I've been trying to make asset managers to manage content for my game engine, and I'm using lua and luabind for my scripting. Getting everything to compile, binding classes and variables, and getting basic variables back from lua have been no ...

I need a tool to parse Lua tables, preferrably in Ruby or Java.

Hello guys, I need a tool to parse Lua table expressions. If all else fails, I will eventually just code a small Lua module to convert tables to XML, but for the time being, I am interested in a Ruby library doing that, but failing that, I would accept tool in any language, provided I can look at its source. Here is an example snippet (...

Free Chess AI library, ideally in Lua (or something easily translatable to Lua)?

Title says it all. A full game or application is not needed; just a core library that ideally can: be competitive against a human have configurable difficulty have customizable moves (I might need some unique moves that don't exist in traditional chess) The platform is a closed system that can only run Lua, so I don't even have acces...

Passing non-Global C++ objects to Lua functions (Swig)

I am extending an interface with lua, and I've run into a problem in that I would need to pass pointers to objects to the lua code to work upon. These classes will have been wrapped via SWIG, and I could instantiate them via lua using swig, but that would leave me with useless objects. I need to be able to pass a callback object to lua,...

SWIG_NewPointerObj and values always being nil

I'm using SWIG to wrap C++ objects for use in lua, and Im trying to pass data to a method in my lua script, but it always comes out as 'nil' void CTestAI::UnitCreated(IUnit* unit){ lua_getglobal(L, "ai"); lua_getfield(L, -1, "UnitCreated"); swig_module_info *module = SWIG_GetModule( L ); swig_type_info *type = SWIG_TypeQ...

First character uppercase Lua

Does Lua provide a function to make the first character in a word uppercase (like ucfirst in php) and if so, how to use it? I want keywords[1] to be first letter uppercase. I've read that string.upper does it but it made the whole word uppercase. ...

shared_ptr requires complete type; cannot use it with lua_State*

Hello! I'm writing a C++/OOP wrapper for Lua. My code is: class LuaState { boost::shared_ptr<lua_State> L; LuaState(): L( luaL_newstate(), LuaState::CustomDeleter ) { } } The problem is lua_State is incomplete type and shared_ptr constructor requires complete type. And I need safe pointer sharing. (Funny thing bo...

Lua : Dynamically calling a function with arguments.

Using Lua, I'm trying to dynamically call a function with parameters. I want to send a string to be parsed in a way that: 1st argument is a class instance "Handle" 2nd is the function to be called All that is left are arguments "modules" is a a table like { string=<instance of a class> } split() is a simple parser that returns a tabl...

Lua - initializing

Hello, I can't init lua correctly under Arch Linux. Lua - latest version. Here is my code: #include <stdio.h> extern "C" { #include <lua.h> #include <lauxlib.h> #include <lualib.h> } int main() { lua_State *luaVM = luaL_newstate(); if (luaVM == NULL) { printf("Error initializing lua!\n"); return ...

What is the Lua equivalent of Twisted Python, Eventmachine for Ruby, NIO for Java, etc.?

What is the Lua equivalent of Twisted Python, Eventmachine for Ruby, NIO for Java, etc.? If there is none, how does one do non-blocking event-based network I/O? In general, how does one solve the C10K problem in Lua? Thanks! ...

Configure lua prosody for localhost only

I want to use prosody or maybe another xmpp server to test my xmpp bot. I want it to only accept connection from the address/localhost(don't want to configure firewall to block access). I would like to know the easiest way to accomplish this. ...

Is there a (simple) way to get the memory usage of a lua table?

I'd like to find out how much memory a lua table is using - without iterating through the table contents and counting up the usage. Is there a lua 5.1 function or 3rd party library that could help with this. Thanks! ...