简体   繁体   中英

Bind existing C variable to Lua using Lua C API

Few years ago I used luabind for binding C++ objects to Lua and vice versa. There was a way to bind existing (allocated through new operator in C++ code) object to Lua and using it in a script like:

binded_object.property = new_value

Now I am working on a new project where I would like to add some scripting. For the sake of simplicity no boost or any heavy templates are desired. So my question is how to do it using only Lua C Api?

Unfortunately, all examples I encountered show how to bind custom C++ type to Lua and then create a new object of that type in the script and finally return the object to C++.

You want SWIG . No Boost, no heavy templates, just all the bindings you could ever want, autogenerated for your convenience.

Now, your question isn't totally clear: by "only Lua C Api", you might mean "making all the Lua C API calls manually in code I write myself". If that's what you mean, take it from someone who's been there: you don't actually want to do that . It's difficult and unrewarding, and you get nothing whatsoever in exchange. Use SWIG. If you want, you can manually edit the bindings it generates, but use SWIG.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM