vc++ express with lua

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Mr.Clean
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 7
Joined: Mon Jan 26, 2009 3:45 am

vc++ express with lua

Post 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 ^_^
User avatar
Kros
Chaos Rift Regular
Chaos Rift Regular
Posts: 136
Joined: Tue Feb 24, 2009 4:01 pm
Current Project: N/A
Favorite Gaming Platforms: PC, Playstation/2/3
Programming Language of Choice: C++
Location: Oregon,USA
Contact:

Re: vc++ express with lua

Post 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?
Isaac Asimov wrote:Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest.
YouTube Channel
Mr.Clean
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 7
Joined: Mon Jan 26, 2009 3:45 am

Re: vc++ express with lua

Post 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

:(
User avatar
Kros
Chaos Rift Regular
Chaos Rift Regular
Posts: 136
Joined: Tue Feb 24, 2009 4:01 pm
Current Project: N/A
Favorite Gaming Platforms: PC, Playstation/2/3
Programming Language of Choice: C++
Location: Oregon,USA
Contact:

Re: vc++ express with lua

Post 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
Isaac Asimov wrote:Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest.
YouTube Channel
Mr.Clean
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 7
Joined: Mon Jan 26, 2009 3:45 am

Re: vc++ express with lua

Post 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?
User avatar
Kros
Chaos Rift Regular
Chaos Rift Regular
Posts: 136
Joined: Tue Feb 24, 2009 4:01 pm
Current Project: N/A
Favorite Gaming Platforms: PC, Playstation/2/3
Programming Language of Choice: C++
Location: Oregon,USA
Contact:

Re: vc++ express with lua

Post 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.
Isaac Asimov wrote:Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest.
YouTube Channel
Mr.Clean
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 7
Joined: Mon Jan 26, 2009 3:45 am

Re: vc++ express with lua

Post by Mr.Clean »

Mr.Clean hugs Kros and says, thank you kind sir :bow:
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: vc++ express with lua

Post 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.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Post Reply