3

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++.

10
  • 1
    For the sake of simplicity no boost or any heavy templates are desired. Boost was made to simplify things, y'know? And my Lua API wrapper with something what you would call "heavy templates" fits in about 500 LoC. Commented Feb 23, 2013 at 0:49
  • I do realise it was made to simplify things. Also I like boost but not for this particular project. The goal is not to use any dependencies but Lua itself. Commented Feb 23, 2013 at 8:42
  • Is standard library also a dependency for you? Commented Feb 23, 2013 at 10:43
  • Does it really matter? The question is how to do it using Lua C Api without boost nor templates. Commented Feb 23, 2013 at 11:51
  • I assume then you aren't going to use standard library containers (like vector, set etc.) too, because they use templates? I could probably answer your question, but requirements are unclear. Commented Feb 23, 2013 at 11:55

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.