Sdl + lua

Hi all,
I need to interact with lua scripts but I found some problem. Since the
project in SDL is a windows application (no console), if I use the function
print(“hello”), the application hangs.

How can I use the LUA scripting with SDL? Some tutorial or article is
published?

Thanks for all

Ferran Ferri
RedSauce S.L.–
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.14.21/235 - Release Date: 19/01/2006


LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y m?viles desde 1 c?ntimo por minuto.
http://es.voice.yahoo.com

Hi all,
I need to interact with lua scripts but I found some problem. Since the
project in SDL is a windows application (no console), if I use the function
print(“hello”), the application hangs.

I think hanging is unusal regardless if its a Windows app. Out of
curiosity, does your application hang if you call printf() directly in
your C code? If so, did you compile Lua yourself or did you download a
prebuilt version? I remember I had a problem with using a prebuilt
version of Lua once. It was compiled under a Borland compiler and I
was using VC6 at the time. Anytime I made any I/O call in Lua, my
program would crash. Rebuilding my own Lua with my own compiler made
the problem go away.

As far as the Windows console, I can’t remember what the default
behavior is. You can check the SDL mailing list archives for this
topic as it has come up before. I think in some cases, stdout/stderr
are redirected and written to stdout.txt/stderr.txt in your current
path which means you can just open the .txt files to see the output.
Also, in visual studio, there was a compile switch you could invoke
which would actually allow a console to be brought everytime you ran
but I forgot what this was.

You can also go to the effort of writing your own in-game console (or
finding a library that does this) like Quake. Then remap or invent
your own print function in Lua that prints to this in-game console
instead of stdout/stderr.

-Eric

THX Eric, but the line that crash my program is

lua_baselibopen(ls);
if (lua_dofile(ls,“script.lua”)==1) {
log->Write(COLOR_RED,“Unable to load script”);
exit(0);
}

Where the lua script has lines refered to console like print(“Hello”). I
suppose that the error is because the lua can access to console as the
application is SDL based.

Ferran Ferri
RedSauce S.L.

|-----Mensaje original-----
|De: sdl-bounces+ferranferri=yahoo.es at libsdl.org [mailto:sdl-
|bounces+ferranferri=yahoo.es at libsdl.org] En nombre de E. Wing
|Enviado el: s?bado, 21 de enero de 2006 0:47
|Para: sdl at libsdl.org
|Asunto: [SDL] Re: SDL + LUA
|
|> Hi all,
|> I need to interact with lua scripts but I found some problem. Since the
|> project in SDL is a windows application (no console), if I use the
|function
|> print(“hello”), the application hangs.
|
|I think hanging is unusal regardless if its a Windows app. Out of
|curiosity, does your application hang if you call printf() directly in
|your C code? If so, did you compile Lua yourself or did you download a
|prebuilt version? I remember I had a problem with using a prebuilt
|version of Lua once. It was compiled under a Borland compiler and I
|was using VC6 at the time. Anytime I made any I/O call in Lua, my
|program would crash. Rebuilding my own Lua with my own compiler made
|the problem go away.
|
|As far as the Windows console, I can’t remember what the default
|behavior is. You can check the SDL mailing list archives for this
|topic as it has come up before. I think in some cases, stdout/stderr
|are redirected and written to stdout.txt/stderr.txt in your current
|path which means you can just open the .txt files to see the output.
|Also, in visual studio, there was a compile switch you could invoke
|which would actually allow a console to be brought everytime you ran
|but I forgot what this was.
|
|You can also go to the effort of writing your own in-game console (or
|finding a library that does this) like Quake. Then remap or invent
|your own print function in Lua that prints to this in-game console
|instead of stdout/stderr.
|
|-Eric
|
|_______________________________________________
|SDL mailing list
|SDL at libsdl.org
|http://www.libsdl.org/mailman/listinfo/sdl

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.14.21/235 - Release Date: 19/01/2006

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.14.21/235 - Release Date: 19/01/2006


LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y m?viles desde 1 c?ntimo por minuto.
http://es.voice.yahoo.com

lua_baselibopen(ls);
if (lua_dofile(ls,“script.lua”)==1) {
log->Write(COLOR_RED,“Unable to load script”);
exit(0);
}

Where the lua script has lines refered to console like print(“Hello”). I
suppose that the error is because the lua can access to console as the
application is SDL based.

As I said, I don’t think this is supposed to be a problem. I actually
do this all the time in my own code.

So again, in your C/C++ code, what happens if you call
printf("Hello);? Does it also hang?

What if you completely remove your current script and replace it with
a single line of code?
print(“Hello”)
What happens if you replace this single line of code with:
foo = 1+1
(so there are no I/O calls)

What if you create your own new C print function and register it with
your lua script and use that instead? (Typed in mail so beware)
/* Crappy print that only prints one string /
static int my_print(lua_State
L)
{
printf("%s\n", lua_tostring(L, -1);
return 0;
}

// Somewhere in your setup code
lua_pushcfunction(ls, my_print);
lua_setglobal(ls, “myprint”);

– In Lua code
print = myprint; – override the default print if you want
myprint(“hello”)

-Eric> From: “Ferran Ferri”

Sorry for spam, just testing if my posts arrives.
Have a feeling that something is wrong, and I can’t post to the mail-list.

Hi Eric, I’ve tested all this situations:

|> From: “Ferran Ferri” <@Ferran_Ferri>
|> lua_baselibopen(ls);
|> if (lua_dofile(ls,“script.lua”)==1) {
|> log->Write(COLOR_RED,“Unable to load script”);
|> exit(0);
|> }
|>
|> Where the lua script has lines refered to console like print(“Hello”). I
|> suppose that the error is because the lua can access to console as the
|> application is SDL based.
|
|As I said, I don’t think this is supposed to be a problem. I actually
|do this all the time in my own code.
|
|So again, in your C/C++ code, what happens if you call
|printf("Hello);? Does it also hang?
|

No, the text goes to a text file named “stdout.txt”

|What if you completely remove your current script and replace it with
|a single line of code?
|print(“Hello”)

Now the application hangs

|What happens if you replace this single line of code with:
|foo = 1+1
|(so there are no I/O calls)

The application finish normally

|What if you create your own new C print function and register it with
|your lua script and use that instead? (Typed in mail so beware)
|/* Crappy print that only prints one string /
|static int my_print(lua_State
L)
|{
| printf("%s\n", lua_tostring(L, -1);
| return 0;
|}
|
|// Somewhere in your setup code
|lua_pushcfunction(ls, my_print);
|lua_setglobal(ls, “myprint”);
|
|-- In Lua code
|print = myprint; – override the default print if you want
|myprint(“hello”)

Uppss!!! This is my solution. I’m learning LUA and I’m an SDL newbie, so
thanks for your patient.

Thanks Eric!!!

|-Eric
|

Ferran Ferri
RedSauce S.L.–
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.14.22/238 - Release Date: 23/01/2006


LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y m?viles desde 1 c?ntimo por minuto.
http://es.voice.yahoo.com

|So again, in your C/C++ code, what happens if you call
|printf("Hello);? Does it also hang?
|

No, the text goes to a text file named “stdout.txt”

Seems reasonable.

|What if you completely remove your current script and replace it with
|a single line of code?
|print(“Hello”)

Now the application hangs

Not good; shouldn’t happen.

|What happens if you replace this single line of code with:
|foo = 1+1
|(so there are no I/O calls)

The application finish normally

Most likely a problem related to the I/O library.

|What if you create your own new C print function and register it with
|your lua script and use that instead? (Typed in mail so beware)

Uppss!!! This is my solution. I’m learning LUA and I’m an SDL newbie, so
thanks for your patient.

This all tells me you are experiencing the same problem I encountered.
I suspect you are using a lua.dll somebody else compiled with a
different compiler (you didn’t tell me if this is true). And for some
unknown reason, the stdio library with the two compilers in question
are not compatible. You should recompile Lua yourself. You shouldn’t
have to remap the print function. Lua’s implementation is nothing
magical and does pretty much exactly the same thing mine does except
that mine sucks. Now you may want to remap the print function to an
in-game console at some point, but for now, recommend trying to fix
this in case there are other hidden problems with your Lua build.

-Eric

Latest Lua distributions (Lua 5.1 at least) have opted for build-all-in-one executable format, which is
Good in the way that it bypasses such printf dependency problems, and is also generally more
manageable at least on the Windows platform.

-asko

Lainaus “E. Wing” :> > |So again, in your C/C++ code, what happens if you call

|printf("Hello);? Does it also hang?
|

No, the text goes to a text file named “stdout.txt”

Seems reasonable.

|What if you completely remove your current script and replace it
with
|a single line of code?
|print(“Hello”)

Now the application hangs

Not good; shouldn’t happen.

|What happens if you replace this single line of code with:
|foo = 1+1
|(so there are no I/O calls)

The application finish normally

Most likely a problem related to the I/O library.

|What if you create your own new C print function and register it
with
|your lua script and use that instead? (Typed in mail so beware)

Uppss!!! This is my solution. I’m learning LUA and I’m an SDL newbie,
so
thanks for your patient.

This all tells me you are experiencing the same problem I encountered.
I suspect you are using a lua.dll somebody else compiled with a
different compiler (you didn’t tell me if this is true). And for some
unknown reason, the stdio library with the two compilers in question
are not compatible. You should recompile Lua yourself. You shouldn’t
have to remap the print function. Lua’s implementation is nothing
magical and does pretty much exactly the same thing mine does except
that mine sucks. Now you may want to remap the print function to an
in-game console at some point, but for now, recommend trying to fix
this in case there are other hidden problems with your Lua build.

-Eric


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

What means “all-in-one executable format”? do you refer to a dll or
an exe file?

Now, I’m trying to recompile Lua in my compiler. I use MS VC++ 7.1

Ferran Ferri
RedSauce S.L.

|-----Mensaje original-----
|De: sdl-bounces+ferranferri=yahoo.es at libsdl.org [mailto:sdl-
|bounces+ferranferri=yahoo.es at libsdl.org] En nombre de askok at dnainternet.net
|Enviado el: mi?rcoles, 25 de enero de 2006 2:39
|Para: A list for developers using the SDL library. (includes SDL-announce)
|Asunto: Re: [SDL] Re: SDL + LUA
|
|
|Latest Lua distributions (Lua 5.1 at least) have opted for build-all-in-one
|executable format, which is
|Good in the way that it bypasses such printf dependency problems, and is
|also generally more
|manageable at least on the Windows platform.
|
|-asko
|
|
|Lainaus “E. Wing” :
|
|> > |So again, in your C/C++ code, what happens if you call
|> > |printf("Hello);? Does it also hang?
|> > |
|> >
|> > No, the text goes to a text file named “stdout.txt”
|>
|> Seems reasonable.
|>
|> > |What if you completely remove your current script and replace it
|> with
|> > |a single line of code?
|> > |print(“Hello”)
|> >
|> > Now the application hangs
|>
|> Not good; shouldn’t happen.
|>
|> > |What happens if you replace this single line of code with:
|> > |foo = 1+1
|> > |(so there are no I/O calls)
|> >
|> > The application finish normally
|> >
|> Most likely a problem related to the I/O library.
|>
|> > |What if you create your own new C print function and register it
|> with
|> > |your lua script and use that instead? (Typed in mail so beware)
|>
|> > Uppss!!! This is my solution. I’m learning LUA and I’m an SDL newbie,
|> so
|> > thanks for your patient.
|>
|> This all tells me you are experiencing the same problem I encountered.
|> I suspect you are using a lua.dll somebody else compiled with a
|> different compiler (you didn’t tell me if this is true). And for some
|> unknown reason, the stdio library with the two compilers in question
|> are not compatible. You should recompile Lua yourself. You shouldn’t
|> have to remap the print function. Lua’s implementation is nothing
|> magical and does pretty much exactly the same thing mine does except
|> that mine sucks. Now you may want to remap the print function to an
|> in-game console at some point, but for now, recommend trying to fix
|> this in case there are other hidden problems with your Lua build.
|>
|> -Eric
|>
|> _______________________________________________
|> SDL mailing list
|> SDL at libsdl.org
|> http://www.libsdl.org/mailman/listinfo/sdl
|>
|
|_______________________________________________
|SDL mailing list
|SDL at libsdl.org
|http://www.libsdl.org/mailman/listinfo/sdl

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.14.22/238 - Release Date: 23/01/2006

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.14.22/238 - Release Date: 23/01/2006


LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y m?viles desde 1 c?ntimo por minuto.
http://es.voice.yahoo.com