🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

problems embedding lua

Started by
40 comments, last by nekoflux 20 years, 5 months ago
I wasn''t aware of any static libs coming with the LUA5.0 package; the files in the "lib" directory are actually internal LUA libs that you load from within LUA, if that''s what you mean.

This link on C++ binding may be of use.
Advertisement
It worked, the examle you sent me built with no problems!!

stupid frickin lua documentation, it makes no mention of lua_dofile(...) and the function they tell you to use doesnt even exist.... go figure.

thanks again man, you prob saved me a few days of headaches, easily!!
nekoflux
Glad to help; as I said - the start of your headaches are just beginning - lua can really be a pain. I hope you have a lot more luck than I ever did!
I personally haven''t had any problems with it. It hasn''t been a headache at all. I use Lua for all sorts of things in my game--enemy behavior, item and useable object behavior, level construction, random treasure generation, etc... Never had a single problem.

The key lies in finding a good tool to help automatically generate code bindings so you don''t have to deal with all the stack manipulations. Personally, I use tolua, but there are a number of tools that can be used.

Golem

Blender--The Gimp--Python--Lua--SDL
Nethack--Crawl--ADOM--Angband--Dungeondweller
So I managed to get lua integrated into my code, and wrote 2 stubs to test calling lua from my code and calling my code from lua. They work perfectly!

Vertex, can you explain what you mean by using tolua to do auto binding? I was just assuming I would have to manually expose a billion functions in my engine to the lua interface. Is this not a wise idea? what does tolua offer?
nekoflux
hey vertex:

do you have a project page I can look at?
nekoflux
For the C++ intergration i''m currently using LuaBind ( http://luabind.sourceforge.net/ ), once i got over my inital stupidness i''ve found it very easy to use
Tolua is a utility to do automatical binding. It works like this:

All functions/structures/variables/classes/definitions you want to expose to Lua are put into one header file in their usual declaration form. Then, tolua is executed. Tolua reads this file and creates another file - C++ source code. This source is added to your project. It has only one (well, two) functions - tolua_something_open(*luaVM) and tolua_something_close(*luaVM), or something like that. Open() activates the binding, close() deactivates.
When compiled, you can write the functions in lua in the exact form as in C and you get the same behaviour.

Well, this is actually what tolua is about. It is very useful and simple. But, unfortunately, it''s available only for Lua 4 (as far as I know).
Society's never gonna make any progress until we all learn to pretend to like each other.
You might also want to check out http://lua-users.org/wiki/SimplerCppBinding for some info on binding classes if you want to do this yourself (Though it''s a bit on the heavy side if you''re just starting out with Lua). In fact the whole Lua Wiki is a big source of information (http://lua-users.org/wiki/).

As for using Lua, I''ve had good experiences with it, I''ve used it for anything from configuration to using it as plugins to just using it to extend game functionality. Besides that I''ve used it in my engine, MFC apps and even embedded it in a Jedi Academy mod for server control. Once you figure out how Lua actually handles things internally, using it becomes much easier.
Prosser: But the plans were on display.Arthur Dent: On display? I eventually had to go down to the cellar.Prosser: That's the display department.Arthur Dent: With a torch.Prosser: The lights had probably gone.Arthur Dent: So had the stairs.Prosser: But you did see the notice, didn't you?Arthur Dent: Oh, yes. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign outside the door saying "Beware of the Leopard." Ever thought of going into advertising?
And, when talking about binding packages, there is CaLua. I didn''t actally use this one and I''m not going to, but I read its documentation and it seems to be working in an entirely different way than tolua. It doesn''t generate any binding files, it rather stands as some kind of interface between Lua and C. I can''t tell any more because as I said I only read the manual once, but you might be interested.
Society's never gonna make any progress until we all learn to pretend to like each other.

This topic is closed to new replies.

Advertisement