• Content count

  • Joined

  • Last visited

Community Reputation

2224 Excellent

About Kaptein

  • Rank
  1. I actually haven't tried that interface yet. All I wanted to do was pass a memory address to Lua, which Lua should interpret as opaque and just pass back as parameters to my engine interface. I will probably try the class-like method at some point and see how useful it is.
  2. POSIX has usleep which can sleep for microseconds, although if the sleep is very short its probably just a pause loop. If you are using a non-decade-old compiler you'll also have access to: std::this_thread::sleep_for(std::chrono::microseconds(usec)); in C++, which will be portable.. if that means anything to you
  3. I solved this, for now, by passing uintptr_t around. Thought about putting the objects index into the 16 unused address bits, but I haven't needed it yet. It's very strange though, that LuaBridge can't pass even void* around. I would understand it if it tried to translate objects (I've seen the more complex usage), but void* should just be passed around as an opaque pointer, which is what it was designed as. Disappointing too. And why am I not Prime Members anymore
  4. Hey, I am currently using LuaBridge as the C++ interface to Lua, and I'm having trouble passing a simple pointer to Lua (as a unique identifier for an object) and then back again. The Lua script calls "object(...)" which returns a pointer, and the pointer is stored in a local: "local obj = tbl.object(....)". If I then proceed to use the variable obj for anything, it's always "nil". What's going on here? I would think this was the most basic and repeating pattern in Lua scripting to use memory addresses as identifiers as well as simplify access to engine internals. static Object* object(int x, int y, int w, int h, int floor) { auto obj = std::make_unique<Object> (gworld(), x, y, w, h, floor); gworld().objects().add(std::move(obj)); return obj.get(); } ... static void object_frame(LuaRef id, int tex, int x, int y, int w, int h) { printf("object_frame(%p, tex=%d)\n", id.cast<Object*> (), tex); } ... gns.beginNamespace("dm") .addFunction("object", object) ... local obj = dm.object(x,y, 8,8, 0) dm.object_frame(obj, gui.tex, 80 + 9*idx,0, 9,8) The value of id, which should just be a memory address, in the "object_frame" function is always nil.