• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
JoshuaWaring

Lua integration with C++ pointers

4 posts in this topic

I'm trying to share pointers into lua (not for lua to use) but to pass back into the program when required, can I just return the pointer as a integer and then return it back to the program as a integer? the only problem I can see is if I compile as 64bit, the pointer becomes the size of a long which would overflow the integers, meaning only 32bit would match lua and work. am I right in thinking this or does someone have tutorial on implementing c++ objects into lua to be used without constant function calls to get the variables of a pointer on the c++ side.

 

Edit: the question wasn't really specific, does anyone have a methodology of exposing C++ objects to Lua?

Edited by Joshhua5
0

Share this post


Link to post
Share on other sites

I'm a bit confused. You say you want to share a pointer with Lua, but not because Lua should use it?

 

It's possible to save a C++ (smart) pointer in a Lua variable for easier access. If you would be using for example this wrapper that would require one line of code. Could you please explain what you mean?

1

Share this post


Link to post
Share on other sites

I want to pass a pointer of a entity to lua, so the lua can then pass the entity pointer into a function.

0

Share this post


Link to post
Share on other sites

You can pass pointer with lua_pushlightuserdata(). Lua won't be able to do anything with it, except passing it around.

Edited by vstrakh
1

Share this post


Link to post
Share on other sites
Light user data is the way to go if you literally just want to pass a pointer around. That's all a light user data is: a void* that is passed around in Lua values which can't be manipulated or modified by Lua itself.

A problem with light user data, however, is that you can't tell what _kind_ of pointer it is. It really is just a void*. So a C++ function bound to Lua could have _any_ light user data passed to it and you have no way to distinguish whether it's a GameObject* or a Texture*, unless you build your own system outside of Lua to identify these objects from a void*.

Full user data lets you attach a unique metatable to values which can be used to distinguish the types of the pointers they wrap. When you retrieve the void* encapsulated by the user data you can also grab the metatable and make sure it matches the one you expect so that you can tell those game objects and textures apart. Full user data is heavier-weight than "light" user data (obviously). There was a patch posted recently to the Lua user list that added a way to type-tag light user data without the overhead of full user data, if you really need the extra performance (you very well might not).
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0