Jump to content
  • Advertisement
Sign in to follow this  
CodyShort

Problem with lua and C++

This topic is 2700 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive been trying to get lua and C++ to work together for a few days now. I have had a little bit of success but I'm having what I'm pretty sure is some linking issues.
I've followed a few tutorials, but none in my particular IDE or on my OS.
I can open the interpreter fine.. I have issues when I try to actually use the interpreter. Errors like this..

/home/cody/luatest.cpp|12|error: ‘lua_openlibs’ was not declared in this scope|


here is my code::

extern "C" {
#include "lua5.1/lua.h"
#include "lua5.1/lauxlib.h"
#include "lua5.1/lualib.h"
}
#include <stdio.h>

int main(int argc, char* argv[ ])
{
lua_State* lua = lua_open();

lua_openlibs(lua);

return 0;
}



I'm only linking lua5.1 which is probably part of the problem. I could possibly be missing a header file also.
Thanks guys

Share this post


Link to post
Share on other sites
Advertisement
openlibs is part of the the auxiliary library. All functions in the aux library is prefixed with luaL_, so the function you are looking for is "[font=monospace]

luaL_openlibs[/font]". The Lua reference manual is a great source for checking whether a function has lua_ or luaL_ prefix, which parameters it takes and so on.

Share this post


Link to post
Share on other sites
Ahhhhh.. perhaps I shouldnt be watching low resolution tutorials on youtube XD. Thanks. and I looked at the lua documentation. should have looked at the reference. my mistake

Share this post


Link to post
Share on other sites
Something I see from Lua tutorials which you have copied is the use of 'lua_open', it has been depreciated for some time and IIRC removed from 5.2

Share this post


Link to post
Share on other sites

Okay, but it isnt depreciated in lua 5.1 correct? (the version i have)


lua_open is a 5.0 function that was depreciated in 5.1 for luaL_newstate and lua_newstate, again IIRC lua_open is just a define for lua_newstate in 5.1.

Share this post


Link to post
Share on other sites

[quote name='Coder4Life95' timestamp='1304294632' post='4805210']
Okay, but it isnt depreciated in lua 5.1 correct? (the version i have)


lua_open is a 5.0 function that was depreciated in 5.1 for luaL_newstate and lua_newstate, again IIRC lua_open is just a define for lua_newstate in 5.1.
[/quote]

this is why i need to stop being lazy watching tutorials and read documentation thoroughly. correct?

Share this post


Link to post
Share on other sites
If your intention is to use Lua as a scripting language in a C++ engine, I recommend looking into a Lua/C++ binding library instead of trying to roll out your own solution. A few years back we were at the same spot, and the programmer on our team who was assigned to integrate Lua and C++ told me that he wanted to try doing it from scratch on his own. I reluctantly gave him the ok, but he never got very far and left the project a few months later. We scrapped everything he did because it was just way too much work that we didn't need to do, and after looking at our options we went with the Luabind library and it has served our needs extremely well. I highly recommend it.


Reading the Luabind documentation and the PIL (Programming in Lua) book that's freely available on the Lua website were all that we needed to put together our solution.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!