Page 1 of 1

vc++ express with lua

Posted: Thu Mar 12, 2009 7:04 am
by Mr.Clean
when i follow the tutorial at http://gamedevgeek.com/tutorials/gettin ... d-with-lua with vc++ express, i can compile the program without errors but when i execute the program from the ide the lua script doesn't run.

on the other hand, when i go to the debug folder where the exe is and run the exe, the lua script runs.

so my question is... why doesnt the lua script run when i execute the program from the ide?

ps: this is my first time posting in this community so ... um ... hi ^_^

Re: vc++ express with lua

Posted: Thu Mar 12, 2009 7:37 am
by Kros
Mr.Clean wrote:when i follow the tutorial at http://gamedevgeek.com/tutorials/gettin ... d-with-lua with vc++ express, i can compile the program without errors but when i execute the program from the ide the lua script doesn't run.

on the other hand, when i go to the debug folder where the exe is and run the exe, the lua script runs.

so my question is... why doesnt the lua script run when i execute the program from the ide?

ps: this is my first time posting in this community so ... um ... hi ^_^
Firstly, welcome to the boards, glad to have you here.

Second, could you be more specific with what happens when you run from VS? If the script doesn't run, then what does happen?

Re: vc++ express with lua

Posted: Thu Mar 12, 2009 7:49 am
by Mr.Clean
If the script doesn't run, then what does happen?
the rest of the code runs but not the script. for example, in the case of the tutorial from the link above, the output should be:

hello world
press enter to exit

but instead i just get:

press enter to exit

:(

Re: vc++ express with lua

Posted: Thu Mar 12, 2009 8:54 am
by Kros
Try replacing your main with this. luaL_dofile() should return 0 if theres no issues with the script, if there is it'll return 1. Might be encountering an error with your script and you wouldn't even know it.

Code: Select all

int main ( int argc, char *argv[] )
{
	/* initialize Lua */
	L = lua_open();

	/* load Lua base libraries */
	luaL_openlibs(L);

	/* run the script */
	if(luaL_dofile(L, "test.lua") == 1)
	{
		printf("Error: %s\n",lua_tostring(L,-1));
		getchar();
		return 1;
	}

	/* cleanup Lua */
	lua_close(L);

	/* pause */
	printf( "Press enter to exit..." );
	getchar();

	return 0;
}
Edit: Forgot that you successfully ran it from the debug folder; I'd give the above a shot anyway but, I doubt that's the problem. I'm out of ideas. Someone else with more lua integration experience might be able to shed some light on the issue.

source: http://www.nabble.com/Reporting-error-m ... 47566.html

Re: vc++ express with lua

Posted: Thu Mar 12, 2009 10:51 am
by Mr.Clean
yep, got an error message:

Error: cannot open test.lua: No such file or directory

which i think means ... the ide is looking for the script in a directory that isn't in the debug folder?

Re: vc++ express with lua

Posted: Thu Mar 12, 2009 11:23 am
by Kros
Mr.Clean wrote:yep, got an error message:

Error: cannot open test.lua: No such file or directory

which i think means ... the ide is looking for the script in a directory that ins't in the debug folder?
Correct. Put the .lua file where the code files are located.

Re: vc++ express with lua

Posted: Thu Mar 12, 2009 11:30 am
by Mr.Clean
Mr.Clean hugs Kros and says, thank you kind sir :bow:

Re: vc++ express with lua

Posted: Thu Mar 12, 2009 3:21 pm
by MarauderIIC
BTW you can put them in whatever folder you want as long as you change your project's working directory settings. Same with all external files :)

Oh yes, and welcome to the forums.