lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


<-- \code\ -->
#include <stdio.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include "mtx.luc.h"

int main(int argc, char *argv[])
{
	int a;

	// Open Lua and its libraries
	lua_State *L = lua_open();
	luaopen_io(L);

	// Run!
	if (luaL_loadbuffer(L,(const char*)B1,sizeof(B1),"mtx.luc")==0)
	{
		
		lua_pushstring(L, "arg");
		lua_createtable(L, argc, 0);

		for (a = 0; a < argc; a++)
			lua_pushstring(L, argv[a]);

		lua_settable(L, LUA_GLOBALSINDEX);

		if (lua_pcall(L, 1, 0, 0) != 0)
			puts(lua_tostring(L,-1));
	}

	// Close Lua and exit program
	lua_close(L);
	return 0;
}
<-- /code/ -->

It gives me error:

PANIC: unprotected error in call to Lua API (no calling environment)

However, if I remove the luaopen_io() call, I get:

?:0: attempt to index global 'io' (a nil value)

Any ideas why? I found an Internet post, and it got solved, but the guy didn't say how. >:-@

Thanks in advance!