• Content count

  • Joined

  • Last visited

Community Reputation

2224 Excellent

About Kaptein

  • Rank
  1. I need some advice. After I changed my scripting language from in-memory C to Lua I've had numerous problems I've never encountered in other languages. Prototypes? Type signatures? Calling functions with any number of parameters? How do you deal with all the random bugs you can get that you have really no way of determining the cause of? If I call a function with one less parameter than it should have, I might just get a Lua error somewhere else in the script. At a later time. What do you do to make your code (which isn't bottlenecked at all, so there is tons of room to add checks and balances) more correct and more sane? If I scripted sanely in C I would rarely have these issues. For example any pointers passed between the engine and the script goes through a sanitizing stage where it actually checks if the pointer points to an actual valid existing entity. If it sounds like I am regretting the change, I don't know how to answer that. Lua can construct tables and pass them around, which is very nice, unlike C where I would have to malloc (and that is just not going to happen).
  2. 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.
  3. 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
  4. 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
  5. 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.