Questions tagged [lua-userdata]

A Lua type that allows arbitrary C data to be stored in Lua variables. It's used to represent new types created by an application program or a library written in C.

56 questions
9
votes
1 answer

How to register Lua userdata correct from Delphi?

I am still confused about registering Delphi userdata to Lua. To teach me the principle I tried to implement a Date(Time) type. At the beginning this type should have three functions accessible to Lua: A new function to create variables of this…
6
votes
1 answer

Lua userdata array access and methods

I am writing in C a userdata type for use in Lua. It has some array-type properties and various methods aswell. Right now if u is of this type, I use u:set(k,v) resp. u:get(k) to access data and e.g. u:sort() as method. For this I set __index to a…
1k5
  • 342
  • 6
  • 15
6
votes
2 answers

Create new empty userdata from pure Lua

I think I saw somewhere a native function in Lua that can return a new userdata. Does it exist? Is it possible to create custom userdata from normal Lua script?
IS4
  • 11,945
  • 2
  • 47
  • 86
5
votes
2 answers

How free up memory allocated by lua_newuserdata with delete operator?

How can I free memory allocated by lua_newuserdata? I have a class called Foo, and this class has a constructor and desstructor, and I need execute both, but I don't know how to use the C++ operator delete, because I didn't use new to allocate…
user3312225
  • 53
  • 1
  • 4
4
votes
2 answers

Lifetime of Lua userdata pointers

If I create a userdata object and stash it in a table, then get a reference to it in C/C++, for how long is that reference valid? Is the reference in C/C++ guaranteed to be valid for as long as the userdata is held in the table in Lua? Or is there…
Tom
  • 7,269
  • 1
  • 42
  • 69
4
votes
1 answer

LuaJ array/list type safety

So using LuaJ. If I pass, from Java to Lua, a userdata List with type T, Luaj still allows insertion into that array of any type of object via the :add function. For example: Java code: import java.util.ArrayList; import…
Dakusan
  • 6,504
  • 5
  • 32
  • 45
3
votes
2 answers

Accessing Light userdata in Lua

I may be misunderstanding their use or misread the documentation, but how do I access members of a struct or class passed to Lua as light userdata? For example if a vector using the following struct typedef struct Foo { int x; int y; } Foo; was…
Lucas
  • 155
  • 2
  • 7
3
votes
1 answer

What happens if I push userdata twice using the same key?

I would like to know what happens if I push the lightuserdata into the registry twice using the same key. My Code: MyData *x, *y; //let's say these are valid pointers lua_pushstring(L, "my_data"); lua_pushlightuserdata(L, static_cast
Zack Lee
  • 2,784
  • 6
  • 35
  • 77
3
votes
0 answers

Bringing userdata into Lua without C (or how much C do I need to learn to do this)

Hi and thanks in advance. I'm trying to see if there's a way to avoid learning C (which I don't know at all) to turn userdata into a Lua table. I'm using an application which lets users write addons using Lua scripts. These addons can query the…
Liam
  • 33
  • 5
3
votes
1 answer

When is it allowed to call lua_gc in C++ when also using lua_newuserdata

The below example is just to demonstrate the problem/question; in reality I have functions creating and returning many different userdata object, and between some of those I may want to call the Lua garbage collector. Also, I am using Lua version…
3
votes
1 answer

Lua - implement userdata iterator

Lua 5.2 I need to iterate an userdata variable. As I understand, I can do this using getmetatable and __pairs. Like this: for k, v in getmetatable(userdataVariable).__pairs do -- someting end But I get 'attempt to call a nil value' when I'm…
user64675
  • 482
  • 7
  • 25
3
votes
1 answer

Create properties and methods Lua C++

This is rather tricky to explain and I could not find anything on this in the documentation or anywhere on the net so I thought this would be a suitable place for this question. I'm trying to register properties and methods on an object in Lua using…
3
votes
1 answer

Access Lua variables in userdata from the C api

I am working on a project written in C++ which uses Lua as a scripting language. In order to facilitate debugging we implemented a network debugger which receives Lua code, runs it, encodes the return values in Json and sends that string back. I…
Lars Kokemohr
  • 590
  • 5
  • 6
3
votes
1 answer

Lua bindings: table vs userdata

When making Lua bindings for C++ classes, should I return tables or userdata objects? Does anyone know any of the pros and cons for each method?
Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238
2
votes
3 answers

Delete all of my Lua userdata in C++

I'm wondering if it's possible to access all of the userdata "tables" (is it called userdata tables?) and then delete them from Lua because this is my problem: a = Object(5, 5) a:Delete() a:SetPosition(3,3) As you can see first I create an object…
user1188404
  • 75
  • 1
  • 7
1
2 3 4