Advertisement

Problem with lua and C++

Started by May 01, 2011 08:06 PM
6 comments, last by Roots 13 years, 7 months ago
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
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.

Advertisement
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
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
Okay, but it isnt depreciated in lua 5.1 correct? (the version i have)

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

[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?
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.

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

This topic is closed to new replies.

Advertisement