• Advertisement
Sign in to follow this  

lua & C++ problem

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

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

Share this post


Link to post
Share on other sites
Advertisement
I don't know much about lua but...try calling

luaL_openlibs(L);

before

luaopen_base(L);

etc.

Share this post


Link to post
Share on other sites
maybe it can't find the file. try doing an fopen to that filename and seeing if it succeeds maybe?

Share this post


Link to post
Share on other sites
Check the first point of this.

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

Share this post


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

  • Advertisement