lua-userdata

Create new empty userdata from pure Lua

半世苍凉 提交于 2019-12-23 09:31:26
问题 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? 回答1: You may be thinking of newproxy From: http://lua-users.org/wiki/HiddenFeatures newproxy is an unsupported and undocumented function in the Lua base library. From Lua code, the setmetatable function may only be used on objects of table type. The newproxy function circumvents that limitation by creating a zero-size userdata and

create lightuserdata in lua for luaglut glReadPixels

北城以北 提交于 2019-12-13 09:00:56
问题 I'm using luaglut and when I try to use the glReadPixels to capture a frame, I cannot prepare the last input argument for it successfully. This is how I call the function: glReadPixels(0, 0, 250, 250, GL_RGB, GL_UNSIGNED_BYTE, img) The img is where I want to store the frame, but no matter in which type I define img, there's always error. The compiler always wants lightuserdata , but I've searching for several days and seems there is no way to create this type of data within lua. How should I

Accessing Light userdata in Lua

≡放荡痞女 提交于 2019-12-12 21:09:35
问题 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 declared as 'test' and defined as something like x = 413 and y = 612, and pushed with a call lua_pushlightuserdata( L, (void *) &test ) ; What would the Lua code of a function that manipulates or prints x and y look like? 回答1: Light userdata in Lua is

Hand over global custom data to Lua-implemented functions

不羁的心 提交于 2019-12-11 20:33:20
问题 Within my Lua-application I have some own functions defined that are registered with lua_register("lua_fct_name","my_fct_name") so that they are known to the Lua script. Now I have some custom/user data that need to be accessible within my_fct_name() . It is just a pointer to a memory area I manage for my own so I use lua_pushlightuserdata (L,data) to add it to Lua-context. Now it seems I don't have the correct position to add these data. When done right after L was created I can't access the

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

∥☆過路亽.° 提交于 2019-12-11 08:02:58
问题 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 can be used in chunk B as it was in the chunk A . MyBindings.h class Vec2 { public: Vec2():x(0), y(0){}; Vec2(float x, float y):x(x), y(y){}; float x, y; }; MyBindings.i %module my %{ #include "MyBindings.h" %} %include "MyBindings.h" main.cpp

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

帅比萌擦擦* 提交于 2019-12-11 03:19:34
问题 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 = luaL_newstate(); // link lua lib luaL_openlibs(L); // addLuaCPath( L, "./clib/?.dll" ); // lua_pushlightuserdata(L, (void*)g_TestObj.get()); // g_TestObj is a global vars lua_setfield(L, LUA_REGISTRYINDEX, "lua_testobj"); // int err = 0; err = luaL_loadfile( L,

Lua userdata: Unable to have simultaneous array access and methods

好久不见. 提交于 2019-12-10 23:58:37
问题 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 is in Lua, and I attempted a C implementation which seems inelegant, but regardless, it creates a new problem in that my new methods can no longer take arguments, and I get this error: attempt to call method 'asTable' (a table value) on this Lua

Lua userdata array access and methods

梦想的初衷 提交于 2019-12-10 15:36:47
问题 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 table containing these methods. Now if I want to access the data using u[k] = v or u[k] , I need to set __newindex and __index to set resp get . But then the other methods are no longer accessible... What's the best way to deal with this in C? I am