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
1
vote
1 answer

How do I set up a metatable to inherit from another metatable while at the same time changing the userdata to another type?

This is something I want to do in C++ using the Lua C API. I'm trying to figure out a good way to make userdata derive from a base userdata object. I want to be able to do this: local item = me:GetCurrentItem() print(item:GetPos()) instead…
CapsAdmin
  • 95
  • 2
  • 7
1
vote
1 answer

Is it possible to dump the properties/methods of a type userdata variable?

Hi I'm wanting to get all the properties and methods of a type function that returns userdata. The documentation on the API i'm using is quite poor, and I know there are more stuff not documented. local w = gui.CreateWindow(...) -- "returns…
noobyy
  • 123
  • 9
1
vote
0 answers

C++ - How to define userdatum with Lua table as member?

I have a userdatum called LuaSettings. This userdatum, except functions, has one member - raw. The raw member is a common Lua table. The usage of this is following: First, userdatum is pushed on the stack as variable settings Then Lua file is…
Sherlock Holmes
  • 191
  • 1
  • 8
1
vote
1 answer

Efficient custom datatype in Lua

I need a 2d vector-like data structure for use in Lua. So far I've found several solutions to this problem: Classic solution of defining the datatype in pure Lua -- the disadvantage is that all operations on it (like addition) need to create a new…
Kornel Kisielewicz
  • 55,802
  • 15
  • 111
  • 149
1
vote
2 answers

How to pass userdata from one Lua chunk to another in C++

I'm trying to get userdata from a Lua script(chunk A) in C++(through a returned variable from function in my example) and then, later pass this userdata back to Lua script(chunk B) from C++(through a function argument in my example) so the userdata…
Zack Lee
  • 2,784
  • 6
  • 35
  • 77
1
vote
1 answer

Lua userdata not available

I have some relatively simple Lua code, which links to some C and some Lua. local messages = {"Hello World!", "This is some test text", "This is a very long piece of test text with no sense of punctuation or common decency because I want to line…
James
  • 2,483
  • 2
  • 24
  • 31
1
vote
1 answer

Setting userdata as namespace in Lua

I have researched this subject and tried various approaches but I can't implement the behavior I have in mind (I'm not even sure it's possible). Basically, I have several userdata objects created in C that can be accessed by their metatable, like…
1
vote
1 answer

Lua: extending userdata in metatables

I am trying to find a proper solution for some protected employee userData that I want extend with additional entries/data for easy access Here's a rough example of what I'm trying to do: This works, but I dont like that I have to put all the custom…
Richard Avalos
  • 555
  • 5
  • 18
1
vote
1 answer

love2D error: unpack expected table got userdata

When I attempt to unpack this table to call on the images, the program returns the error "bad argument to unpack (table expected got userdata)" textures = {love.graphics.newImage("image.png"), love.graphics.newImage("image.png"), …
Noah Jb
  • 87
  • 6
1
vote
1 answer

how to find out the type of userdata when Lua calling C/C++

I'm using Lua to call a dll file. my c/c++ code is like this: #include extern "C"{ #include "lua.hpp" #include "lualib.h" #include "lauxlib.h" } using namespace std; typedef struct StructA{ int a; } structA; typedef…
user1021531
  • 487
  • 1
  • 7
  • 16
1
vote
1 answer

use lua's lightuserdata to register timer callback

I would like to wrap the C timer (not alarm) and use it within lua, in a way that I could specify a callback function to be triggered after one second have passed. In order to use multiple timer, a timer ID and callback will be stored to a…
uudiin
  • 23
  • 2
1
vote
2 answers

Specifying both "methods" and index operator in Lua metatable

I need userdata objects to support both methods and the index operator (with integer indices). Is there a way to achieve this in a common metatable without simulating methods via a function? I tried chaining metatables, by setting…
riv
  • 6,846
  • 2
  • 34
  • 63
1
vote
1 answer

Accessing userdata properties and methods in Lua

I have a question regarding accessing userdata types in LuaInterface. When I pass my C# Dictionary to Lua and try to iterate through it using ipairs I get an error since ipairs is expecting a table and not a userdata object. I suppose one solution…
Anoop Alex
  • 179
  • 1
  • 9
1
vote
2 answers

Save reference to Lua's userdata

#1 Lua: local test = Test(); #2 C: //creating "lua's test" luaL_newmetatable(L, "someTable"); lua_userdata *userData = (lua_userdata *)lua_newuserdata(L, sizeof(lua_userdata)); luaL_getmetatable(L, "someTable"); lua_setmetatable(L, -2); #3…
RolandasR
  • 3,030
  • 2
  • 25
  • 26
1
vote
2 answers

Lua userdata object management

I'm trying to push a Lua class object onto the stack. The pointer to that object can be returned by multiple functions. In other words: I need to push userdata values while still keeping the ability to use '==', '~=' etc. on them so the userdata…
user1478081
  • 11
  • 1
  • 5