Home » Community » Forums » For Beginners » lua & C++ problem
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 lua & C++ problem
Post New Topic  Post Reply 
heey all,

i've tried to embed lua into C++. i'm using this code:
extern "C" {   
#include "lua.h"   
#include "lualib.h"   
#include "lauxlib.h"   
}
#include <stdio.h>
 
int main()   
{   
	int s=0;   
	
	lua_State *L = lua_open();   
	
	luaopen_base(L);
	luaopen_table(L);
	luaopen_io(L);
	luaopen_string(L);
	luaopen_math(L);

	//run a Lua scrip here   
	luaL_dofile(L, "lua/startup.lua");   

	printf("\nI am done with Lua in C++.\n");   

	lua_close(L);   

}



but when i run it i get this error:
Quote:
PANIC: unprotected error in call to Lua API (no calling environment)


any idea's how to solve this error?
i'm using:
Visual C++ 2008
lua 5.1.4

i'm linking to:
lua5.1.lib

 User Rating: 1012   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I don't know much about lua but...try calling

luaL_openlibs(L);

before

luaopen_base(L);

etc.

 User Rating: 1124   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

thanks for the advice but it didn't help.

assainator

 User Rating: 1012   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

maybe it can't find the file. try doing an fopen to that filename and seeing if it succeeds maybe?

 User Rating: 1131   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Check the first point of this.

Try replacing all your luaopen_* calls with just one to luaL_openlibs.

 User Rating: 1611   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may not post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: