lua

Can I force Lua's table indexing from zero?

I've read about Lua, it's almost perfect language, but there was critical error. It's one-based indexing. I read also it has a feature to setting value at index 0, but it's not counted table length and string manipulations are still one-based. So the feature is meaningless. I don't want to flame about one-based or zero based. I'm just a...

Calling lua functions from .lua's using handles?

Hey there, I'm working on a small project trying to integrate lua with c++. My problem however is as follows: I have multiple lua scripts, lets call them s1.lua s2.lua and s3.lua. Each of these has the following functions: setVars() and executeResults(). Now I am able to to call a lua file through LuaL_dofile and immediately after use...

Lua: How to connect & query MySQL from within Lua?

How can I connect to a MySQL database from using Lua programming language? If a good/popular library exists, what is it? ...

What's the Javascript 'delete' keyword equivalent in Lua?

Javascript delete keyword deletes a named variable slot from nearest execution environment which it defined. What's the equivalent in Lua? ...

Solving random crashes

I am getting random crashes on my C++ application, it may not crash for a month, and then crash 10 times in a hour, and sometimes it may crash on launch, while sometimes it may crash after several hours of operation (or not crash at all). I use GCC on GNU/Linux and MingW on Windows, thus I can't use the Visual Studio JIT Debug... I hav...

Using unique dynamic variable names (not variable values!)

Ok so, this is more a sanity check than anything else. Lets asume we have a struct called lua_State, now I need to create a uncertain amount of unique lua_State's. To make sure I don't use the same variable name twice I would need to have some sort of way to get an unique variable every time i make a new state. However there is only on...

How to execute an untrusted Lua file in its own environment from the C API

I want to execute an untrusted .lua file in its own environment by calling lua_setfenv() so that it cannot affect any of my code. The documentation for that function though only explains how to call a function, not how to execute a file. Currently to run the file I use: int error = luaL_loadfile(mState, path.c_str()) || lua_pcall(mSta...

Lua C API and metatable functions

I'm using Lua inside a C application, and I have two tables. I want to create a third table that, while empty, will index values from my first two tables. I wrote the following simple example in Lua - a = { one="1", two="2" } b = { three="3", four="4" } meta = { __index = function(t,k) if a[k] == nil then return b[k] else return a...

Lua Script Pattern Matching Problem

First of all, I have been using this site as a reference through the entire scripting process and it has been wonderful. I appreciate how useful and knowledgeable everyone is here. With that in mind, I have a question regarding matching (pattern matching) in Lua. I am writing a script that essentially takes input from a file and imports ...

Logical 'or' in Lua patterns?

Is it possible to achieve in Lua? local noSlashEnding = string.gsub("slash\\ending\\string\\", "\\|/$", "") -- noSlashEnding should contain "slash\\ending\\string" local noSlashEnding2 = string.gsub("slash/ending/string/", "\\|/$", "") -- noSlashEnding2 should contain "slash/ending/string" The point here is the no acceptance of logic...

Lua as a web language

Hello, I'm building a new game and I need to build a web app to help manage content generation. The app would consist of a couple simple forms that would tie into a MySQL db. I've been really interested in learning Lua for a long time due to it's large popularity in the video game industry and was wondering how well it works as a serv...

in Lua, how can I use a table as varargs (...)?

strjoin accepts one string and then a variable number of arguments. I'm looking for a way to take a table with a variable number of arguments and use each item in the table as another argument. local myTable = { 'a', 'b', 'c', } -- This is what I want except that I don't want to hard code -- a specific number of parameters ...

Is Lua an object-oriented language?

Is this language an OO language? Is it often used as OO language? ...

Pattern match a string in Lua

I have the following string to split into a table using lua: (the data is aligned with each other. I did not find out how to write format it like that on this site) IP: 192.168.128.12 MAC: AF:3G:9F:c9:32:2E Expires: Fri Aug 13 20:04:53 2010 Time Left: 11040 seconds the result should be put into a table l...

Sending variable pointers back and forth between C++ and Lua?

I am looking for a way to transfer the variable addresses back and forth between C++ and Lua. For instance, transferring an object from C++ to Lua and do some processing, then transfer it back to C++. However, the thing is how can you execute a C++ functions or methods from Lua? Or is a workaround required? If possible, could you incl...

Programming Language: What language has both Python & Ruby features?

I came across this great comparison chart between Python & Ruby. I'm looking for a programming language that is truly a blend between Python and Ruby (with a slight lean towards Python). I really like in Ruby that everything is an object (unlike Python). However, I really like in Python that things are immutable, so that code maintenan...

Simple math/programming question. Individual percentage from total.

I'm no good at math. :) Is this right? I'm accumulating all CPU seconds, and I need to find what percentage the addon's CPU time is from the total. function PluginResources.GetTotalCPU(addon) UpdateAddOnCPUUsage() local totalCPU = 0 for i=1, GetNumAddOns() do totalCPU = totalCPU + (GetAddOnCPUUsage(i) ) end ...

String to Table in Lua

I am using LuaSocket and http.request to call a remote PHP script that generates a Lua table and outputs it to the browser. When I store the http.request response in a variable it's a string, which renders the table unusable in my Lua code. For example: eventData = http.request("http://www.example.com/events.php") print( eventData ) ...

Why does Lua have no "continue" statement?

I have been dealing a lot with Lua in the past few months, and I really like most of the features but I'm still missing something among those: Why is there no continue? What workarounds are there for it? ...

What language should we use to let people extend our terminal/sniffer program?

Hello, We have a very versatile terminal/sniffer application which can do all sorts of things with TCP, UDP and serial connections. We are looking to make it extensible -- i.e, allow people to write their own protocol parsers, highlighters, etc. We created a C-like language for extending the product, and then discovered that for some ...