0

I'm working on a game, and i'm using Lua as the scripting language. Lua can only register static functions, and i need to draw things on my main_window. So i need give the pointer of the main function to the static function. I have been researching about pointer to int, and the solution was using intptr_t. It is generally not a good idea to do such a thing like that, but my goal was not to simulate the memory chunk, but to pass pointer to a static function int order of C++ -> Lua -> C++.
I have read something like There will be some problems if I use int depends on system(32 or 64), and I'm not sure what Lua use. I don't need bind object to Lua or something, what i need is a fast/easy mean to let the lua hold the pointer for set and give it to the static method in C++ in time i need it, safely.

MadokaMagica
  • 97
  • 1
  • 9
  • @luiscubal how do i pass that back – MadokaMagica Dec 18 '13 at 16:18
  • `luaL_checkudata`, if I'm reading [this](http://lua-users.org/wiki/UserDataWithPointerExample) right (look at `Image_new`, then `checkImage` and `Image_line` to see how they do it). – luiscubal Dec 18 '13 at 16:26
  • `lua_pushlightuserdata(L, ptr)` on Lua side it will be `userdata`. To get ptr `ptr = (LUA_TLIGHTUSERDATA == lua_type(L, idx))?lua_touserdata(L, idx):NULL;` – moteus Dec 19 '13 at 08:09

0 Answers0