Jump to content
  • Advertisement
Sign in to follow this  
monp

lua in c++

This topic is 4012 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

Hello. I am trying to learn how to use lua with c++, but i dont understand what i am doing wrong to get this little program to work. here is the errors i am getting. undefined reference to `luaL_newstate' and this one undefined reference to `lua_close' now for the code. #include <iostream> extern "C" { #include <lua/lua.h> #include <lua/lualib.h> #include <lua/lauxlib.h> } int main() { lua_State *L = lua_open(); lua_close(L); return 0; }

Share this post


Link to post
Share on other sites
Advertisement
Are you linking to the correct libraries? Specifically, are you linking to the lua library?

If you're using gcc you'll need to add something like -llua to the command line. In other compilers/IDEs you'll somehow need to add the lua library to your linker settings.

You could also check if your lua headers are installed in the right location...

-Raven

Share this post


Link to post
Share on other sites
What version of compiler are you using? I haven't used lua for quite some time thou.

note: you supplied the directories for lua right?

Share this post


Link to post
Share on other sites
Ok. i got it to compile now, but whenever i run it, it says im missing the lua5.1.dll, but i have it right there with the lib files and include files.

[Edited by - monp on October 28, 2007 10:19:30 AM]

Share this post


Link to post
Share on other sites
i got it to compile but i get this error.
here is the code.

#include <iostream>
extern "C" {
#include <lua/lua.h>
#include <lua/lualib.h>
#include <lua/lauxlib.h>
}

int main(int argc, char* argv[])
{
lua_State *L = lua_open();
luaopen_io(L);
luaopen_base(L);
luaopen_table(L);
luaopen_string(L);
luaopen_math(L);
luaL_openlibs(L);


char* strLuaInput = "a = 1 + 1;\nprint ( a);\n";
luaL_dostring(L, strLuaInput);
lua_close(L);
return 0;
}

it says PANIC: unprotected error in call to lua API (no calling enviroment)


[Edited by - monp on October 28, 2007 2:37:29 PM]

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!