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
2
votes
1 answer

How do user values in Lua C API and lua_newuserdatauv function in particular work?

The documentation for lua_newuserdatauv(lua_State *L, size_t size, int nuvalue) says This function creates and pushes on the stack a new full userdata, with nuvalue associated Lua values, called user values, plus an associated block of raw memory…
Sun of A beach
  • 171
  • 1
  • 10
2
votes
0 answers

Lua life cycle of userdata and uservalue

I am creating userdata on Lua 5.3 and setting its uservalue (a table value). When I use collectgarbage() the uservalue is collected, however the userdata is not. Why is the life cycle of userdata and uservalue different? How can I make the uservalue…
renyson
  • 21
  • 2
2
votes
1 answer

Add a method to userdata

I am trying to add a method to an existing userdata like this, this however game me an error. local userData = luajava.newInstance("Objects.Block") --creates a userdata from a Java class userData.newMethod = function() -- Do stuff end I…
Timotheus
  • 2,250
  • 5
  • 29
  • 39
2
votes
1 answer

Convert Userdata to hex in Wireshark Dissector

I'm coding Wireshark Dissector lua script now. How to convert userdata to hex string? I want to get output like this 0102030405060708000a0b0c0d0e0f10 I can convert hex string using tostring. But it omits long data. Output Image How to convert…
bugggy
  • 156
  • 2
  • 10
2
votes
1 answer

Getting reference to userdata in a table using luaL_ref?

First of all, I appologize for not uploading the full code. I'm trying to convert userdata to a pointer so it can be passed to other lua chunk using lua_rawgeti(). If you see outletRet() function, it checks the type of a returned value, and if it's…
Zack Lee
  • 2,784
  • 6
  • 35
  • 77
2
votes
1 answer

How to index a converted userdata value?

I tried to convert C++ class to a void pointer using lua_touserdata() and then convert it back to C++ class using lua_pushlightuserdata(). However, I can't index variables in a class once I do the conversion. Here's my test code: MyBindings.h class…
Zack Lee
  • 2,784
  • 6
  • 35
  • 77
2
votes
1 answer

Lua userdata: Unable to have simultaneous array access and methods

I had this guy's problem: Lua userdata array access and methods wherein when I set the __index of my userdata's metatable, it always called the getter, instead of my other methods that weren't declared for meta-events. The solution to the above link…
Lars
  • 233
  • 2
  • 9
2
votes
1 answer

Storing and Returning Lua Userdata

I have the following classes in C++ class B; class A { B* GetB(); void SetB(B*& b) { _b = b;}; private: B* _b; } And part of the lua binding code: int A::setB(lua_State* L) { A* a = checkA(L,1) // Macro for luaL_checkudata B*…
Moop
  • 3,414
  • 2
  • 23
  • 37
2
votes
2 answers

Lua userdata gc

Is it possible for a piece of Lua userdata to hold reference to a Lua object? (Like a table, or another piece of userdata?). Basically, what I want to know is: Can I create a piece of userdata in such a way taht when the gc runs, the user data can…
anon
  • 41,035
  • 53
  • 197
  • 293
2
votes
2 answers

./lua/addtest.lua:9: attempt to index local 'testobj' (a userdata value)]]

test.exe call addTest.lua and set the lua_testobj to the table, and addTest.lua call testobj.dll, but testobj.dll can not get the "lua_testobj" error msg is addTest.lua:9 attempt to index local 'testobj' (a userdata value) test.exe L =…
Sleepwom
  • 227
  • 6
  • 15
2
votes
1 answer

Lua API push userdata

I'm trying to give a scripting ability to my component system. Of couse each component has a field "parent" which holds access to the parent Actor. I can write the code so I can access my C++ methods from Lua, but I got stuck when I want to return…
RobeeZ
  • 95
  • 9
2
votes
0 answers

Lua light userdata

I have a problem with Lua and I don't know if I going in the right direction. In C++ I have a dictionary that I use to pass parameter to a resource manager. This dictionary is really similar to a map of hash and string. In Lua I want to access to…
ilmale
  • 418
  • 3
  • 12
2
votes
2 answers

How to add a reference to table to userdata object?

I have a function in lua that accepts a userdata object. function Class:AttachToUserdataObject(userdataObject) userDataObject.tableAttached = self end But later on, when I am using the same userdata object, I can't find it -…
Nebril
  • 3,153
  • 1
  • 33
  • 50
2
votes
2 answers

Lua RPC and userdata

I'm currently using luarpc in my program to make interprocess communication. The problem now is that due to my tolua++ binding which stores class instances as userdata im unable to use any of those functions cause luarpc cant handle userdata. My…
ACB
  • 1,607
  • 11
  • 31
1
vote
3 answers

Wireshark dissector in Lua - userdata

I am new to Lua, and I am building a custom dissector for Wireshark. My situation is this: The wireshark data consists of hex numbers such as 4321 8765 CBA9. What I would like to wind up with is (after it has been dissected) : CBA9 8765 4321. What…