Skip to main content
GameDev.net gamedev.net
🔒 Locked

lua & C++ problem

Started by assainator Nov 2, 2009 at 7:46 AM 3 replies 1.1k views
Original Post
assainator
assainator
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
"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

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

luaL_openlibs(L);

before

luaopen_base(L);

etc.
assainator
assainator
thanks for the advice but it didn't help.

assainator
"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

Atrix256
Atrix256
maybe it can't find the file. try doing an fopen to that filename and seeing if it succeeds maybe?
mattd
mattd
Check the first point of this.

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.