lua-users home
lua-l archive

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

I'm just starting to learn Lua and I have what seems to be a very 
simple problem. I'm trying to load a file with a Lua function in it 
and call the function from C code.

Here's my C function:

// Main program function
void main()
	lua_State *lua_state;
	int rc;

	// create lua state object
	lua_state = lua_open();

	// load lua code
	rc = luaL_loadfile(lua_state, "test.lua");
	if (rc) {
		goto main_deinit;

	// call "main" lua function
	lua_getglobal(lua_state, "main");
	lua_call(lua_state, 0, 0);


	// de-initialize lua state object

In the file, "test.lua", I have the following:

function main ()
	i = 0

Now when I run the C program, it looks like the lua_call() function 
doesn't do anything since the previous lua_getglobal() doesn't 
actually find the "main" function. Am I doing something wrong here?