LuaJava problem

 
Post new topic   Reply to topic    mudlab.org Forum Index -> Coding
View previous topic :: View next topic  
Author Message
Aioros



Joined: 16 Jun 2005
Posts: 14
Location: Lisboa, Portugal

PostPosted: Thu Aug 10, 2006 8:13 am    Post subject: LuaJava problem Reply with quote

As i know some people here have worked with Lua before, i post this here hoping someone will be able to help me here.

Some days ago, i decided to have a look at luajava. I went up to the web page, read a bit and then tried to make an example work.

Java code:
Code:
public class Hello
{
    public static void main(String[] args)
    {
        LuaState L = LuaStateFactory.newLuaState();
        L.openBasicLibraries();

        L.doFile("hello.lua");

        System.out.println("Hello World from Java!");
    }
}


Lua code (hello.lua):
Code:
print("Hello World from Lua!")


The 1st problem was that the "Hello World from Java!" was showing before "Hello World from Lua!", and so i searched and found out that i must type "io.flush();" insude the lua code, so the print will be displayed before the java line.

So far so good, but then i messed around with the project, decided to see what would happen if i removed the lua file and this is what was displayed by the program:

Quote:
Hello World from Java!
cannot read hello.lua: No such file or directory


The error happens before the java println, so why is it displayed last?

So I searched again, but this time with no luck.

So, here is the big question: Does anyone have any idea about why this happens, and what is lacking to make it work properly?

Thank you.
Back to top
View user's profile Send private message
Author Message
Kjartan



Joined: 13 May 2005
Posts: 110

PostPosted: Thu Aug 10, 2006 4:09 pm    Post subject: Reply with quote

First, this probably shouldn't be in Meta, but in Coding. However, I can't move it, so I will wait for some helpful moderator to do so.

I think the problem is that the error message about not finding the file is also sent to the same lua output stream that, as you have already seen, doesn't get flushed promptly.

Thus the reason the messages show up out of order is not that they were issued out of order; it's just that lua sat on the "No such file" message for a while, so it didn't appear until the end of the program.

One thing you can do is make a lua file "flush.lua" that does nothing but flush the lua output stream with io.flush. Then, after all of your lua is done, L.doFile("flush.lua"). I'm not absolutely sure that will work, because I know nothing about lua and the different doFile calls might open up totally different io streams, but it's worth a try.
Back to top
View user's profile Send private message Visit poster's website
Author Message
Aioros



Joined: 16 Jun 2005
Posts: 14
Location: Lisboa, Portugal

PostPosted: Fri Aug 11, 2006 10:19 am    Post subject: Reply with quote

I didn't put this in coding, because it is't mud related, so i serched the "talk about whatever you need" board. Razz

Anyway, i had already tried that, but it doesn't work. The error messages are probably not sent to the io channel, thus not being flushed. I also tried err.flush() but aparently Lua doesn't like that. Razz
Back to top
View user's profile Send private message
Author Message
Kjartan



Joined: 13 May 2005
Posts: 110

PostPosted: Fri Aug 11, 2006 3:40 pm    Post subject: Reply with quote

I bet if you do a L.close() immediately after the L.doFile() that will flush the buffers.
Back to top
View user's profile Send private message Visit poster's website
Author Message
Aioros



Joined: 16 Jun 2005
Posts: 14
Location: Lisboa, Portugal

PostPosted: Fri Aug 11, 2006 3:55 pm    Post subject: Reply with quote

The problem there is that the whole Lua environment will probably be destroyed, and if later i need to access another lua function, i'll have to reload it. If i have mud commands, mob AI, whatever in Lua, i wouldn't want to unload it all just to be able to report an error.

I think the error handling is different and i should read a bit about it 1st. As far as i know Eiz has Lua experience, i was hoping i'd hear from him about this subject. Razz
Back to top
View user's profile Send private message
Author Message
Alayla



Joined: 11 May 2005
Posts: 88
Location: Prague

PostPosted: Mon Aug 14, 2006 12:13 pm    Post subject: Reply with quote

Moved topic to coding, enjoy.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    mudlab.org Forum Index -> Coding All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group
BBTech Template by © 2003-04 MDesign