IrrLua

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
MarcoTMP
Posts: 37
Joined: Mon Aug 29, 2005 8:14 pm
Location: Dominican Republic
Contact:

Re: IrrLua-0.7 released

Post by MarcoTMP »

zenaku wrote:MarcoTMP, a new function 'irr.io.dofile(IReadFile)' is now implemented. You can now run scripts out of zip files.
Hey, thanks zenaku :D ,I'll try it when get home.
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

@zenaku, you made great work. I just tested examples and all works very well. Even all is documented.
So, I think that is the time for us to learn more for Lua scripting.
Also, I hope that will be able to translate your stuff for Borland compiler.
ImageImage
Site development -Rock and metal online
--- etcaptor.com ------freenetlife.com
elander
Posts: 193
Joined: Tue Oct 05, 2004 11:37 am

Post by elander »

I have upgraded my little game to this version and didn't have any problems so far.

Is there any other way to launch an irrlua application unless using an msdos box? I would sugest an executable like start.exe that could be renamed and would read a start.ini file (or another name.ini if the file was renamed) to know whats the root lua script to run.

Im not such a big windows programmer so i can't do this myself.
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Post by zenaku »

elander wrote:I have upgraded my little game to this version and didn't have any problems so far.

Is there any other way to launch an irrlua application unless using an msdos box? I would sugest an executable like start.exe that could be renamed and would read a start.ini file (or another name.ini if the file was renamed) to know whats the root lua script to run.

Im not such a big windows programmer so i can't do this myself.
Here's a quick hack you can do to the 'LuaInterpreter' project.

In the LuaInterpreter project settings, under C++/Preprocessor settings, remove the '_CONSOLE' define. Under linker settings, open the system section and change the SubSystem from 'CONSOLE' to 'WINDOWS'.

At the top of LuaInterpreter.cpp, put the line:

Code: Select all

#include <windows.h>
At the very bottom, replace the main() function with this:

Code: Select all


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	lua_State *l = lua_open(); 
	lua_userinit(l);
	int ret = lua_dofile(l, "startup.lua");
	lua_close(l);
	return ret;
}

That will run a script called startup.lua. No console window will be created. You can run any old lua code from the startup script. In my 'startup.lua', I just put

Code: Select all

dofile("01.HelloWorld.lua")
You'll need to be aware that when running under WinMain(), some functionality is missing. For starters, reading input from the console doesn't work (since you don't have a console now).

In the example 02.Quake3Map.lua, at the top I do

Code: Select all


	local answer = io.read("*line")
	local driverTypes = {["a"] = irr.video.EDT_DIRECT3D9,
						 ["b"] = irr.video.EDT_DIRECT3D8,
						 ["c"] = irr.video.EDT_OPENGL,
						 ["d"] = irr.video.EDT_SOFTWARE,
						 ["e"] = irr.video.EDT_SOFTWARE2,
						 ["f"] = irr.video.EDT_NULL }


	local type = driverTypes[answer]
	if type == nil then 
		return 0
Under WinMain() the problem is io.read("*line) returns nil and the program silently terminates. Watch out for issues like that! :)
-------------------------------------
IrrLua - a Lua binding for Irrlicht
http://irrlua.sourceforge.net/
elander
Posts: 193
Joined: Tue Oct 05, 2004 11:37 am

Post by elander »

Would it be possible to change the lua executable to detect when it is being called from dos prompt and when it is being called from explorer and select the apropriate startup method automaticaly? Like i said i don't understand much of windows programming so this is just a wild guess, but it would be very useful if this was possible. I know that some apps can do this and even start as app from a dos window and let the user close the dos window afterwards.
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Post by zenaku »

elander wrote:Would it be possible to change the lua executable to detect when it is being called from dos prompt and when it is being called from explorer and select the apropriate startup method automaticaly? Like i said i don't understand much of windows programming so this is just a wild guess, but it would be very useful if this was possible. I know that some apps can do this and even start as app from a dos window and let the user close the dos window afterwards.
Anything is possible, but doing that is non-trivial.

In the code above, did you notice how the SubSystem crap is built into the compiler?

All windows programs need a WinMain(), even console programs that only implement main(). If your program is a console program and has no WinMain() (like lua.exe), windows gives you one (otherwise there would be no console window at all to display). That's where the subsystem crap comes in, and why it's a pain to change how that stuff works. To make it work how you describe you'd most likely have to make lua.exe implement WinMain() (like I posted above) and then implement your own console IO like stdin stdout, etc (not fun).

It would probably be a lot easier to just have two executables (lua.exe and WinLua.exe? ) and run which ever is appropriate.
-------------------------------------
IrrLua - a Lua binding for Irrlicht
http://irrlua.sourceforge.net/
elander
Posts: 193
Joined: Tue Oct 05, 2004 11:37 am

Post by elander »

zenaku wrote: For example, there is already a LuaZip library that should integrate well with IrrLua.

You could then do something like:

Code: Select all


require "zip"

local zfile, err = zip.open('luazip.zip')

-- print the filenames of the files inside the zip
for file in zfile:files() do
	print(file.filename)
end

-- open myscript.lua and run it
local f1, err = zfile:open('myscript.lua')

dofile(f1)
I tried to download this stuff from the LuaZip site but unfortunalty the only thing they have is a .c file a zip.dll which i assumed it can only be used used to compile to whatever program is enbeding lua.

It would be great if we could install a package by just copying the files zip.lua and zip.dll somewhere the simply use 'require "zip"' in our script.

This would gives an opurtunity to use lua jit:

http://luajit.luaforge.net/

My script startup would be:

luajit.exe main.lua

And in the main.lua source:

require "irrlua"
require "zip"
require "audiare"
require "newton"
require "dustyengine"

function main()
do stuff
end

Do you think this is possible?
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Post by zenaku »

elander wrote:
zenaku wrote: For example, there is already a LuaZip library that should integrate well with IrrLua.

You could then do something like:

Code: Select all


require "zip"

local zfile, err = zip.open('luazip.zip')

-- print the filenames of the files inside the zip
for file in zfile:files() do
	print(file.filename)
end

-- open myscript.lua and run it
local f1, err = zfile:open('myscript.lua')

dofile(f1)
I tried to download this stuff from the LuaZip site but unfortunalty the only thing they have is a .c file a zip.dll which i assumed it can only be used used to compile to whatever program is enbeding lua.

It would be great if we could install a package by just copying the files zip.lua and zip.dll somewhere the simply use 'require "zip"' in our script.

This would gives an opurtunity to use lua jit:

http://luajit.luaforge.net/

My script startup would be:

luajit.exe main.lua

And in the main.lua source:

require "irrlua"
require "zip"
require "audiare"
require "newton"
require "dustyengine"

function main()
do stuff
end

Do you think this is possible?
All of that will be possible with Lua 5.1. The problem with lua 5.0 is there isn't a standard way of dealing with binary modules. You get loadlib() and that's about it. Lua 5.1 addresses that issue, so you can expect prebuilt binary modules for lua to start taking off with Lua 5.1. With Lua 5.0, you have to roll your own, which is what I did with IrrLua.

In IrrLua/pkg/IrrLua_package.lua, you can see how the binary module stuff is done in IrrLua. IrrLua_package.lua is compiled to lua p-code and put in the \bin directory as 'IrrLua.lua'. This way, you can do 'require "IrrLua"' and lua 5.0 runs the the IrrLua.lua file. In that file is where the DLL is actually loaded with loadlib(). I'm planning on moving IrrLua to Lua 5.1 as soon as I can. I just got a new job, so it might take a while. Expect IrrLua development to slow down while I get aquainted with my new job ;)

I don't have my machine set up to test anything, but I just looked at the LuaZip package. I think you can make it work without compiling anything. The Zip.DLL that comes with it is the Lua binding. It's just a matter of loading it. The require keyword won't do it for you, as it only understands Lua files, not DLLs. You'll have to do something similar to what IrrLua does to make the 'require' keyword work with the zip lib.
-------------------------------------
IrrLua - a Lua binding for Irrlicht
http://irrlua.sourceforge.net/
elander
Posts: 193
Joined: Tue Oct 05, 2004 11:37 am

Post by elander »

Thats good news. I will also try the zlib trick with audiere to see if it works. Thanks.
mgphuang
Posts: 3
Joined: Thu Aug 05, 2004 2:38 am

it seem like a bug.

Post by mgphuang »

Code: Select all

function irr.gui.createIGUIElement(type, environment, parent, id, rectangle, def)
	local o = {}
	for i,v in pairs(def) do o[i] = v end
-- the line blow is right?
	o.__c_class = irr.scene.IrrLuaIGUIElement:new()
	tolua.inherit(o, o.__c_class)
	tolua.takeownership(o)
	o.__index = function (t, k) return rawget(t,"__c_class")[k] end	
	setmetatable(o, o)	
	irr.__iguielementproxy[o.__c_class:GetProxy()] = o
	return o
end
and this function can not be call ,a nil value.
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Re: it seem like a bug.

Post by zenaku »

mgphuang wrote:

Code: Select all

function irr.gui.createIGUIElement(type, environment, parent, id, rectangle, def)
	local o = {}
	for i,v in pairs(def) do o[i] = v end
-- the line blow is right?
	o.__c_class = irr.scene.IrrLuaIGUIElement:new()
	tolua.inherit(o, o.__c_class)
	tolua.takeownership(o)
	o.__index = function (t, k) return rawget(t,"__c_class")[k] end	
	setmetatable(o, o)	
	irr.__iguielementproxy[o.__c_class:GetProxy()] = o
	return o
end
and this function can not be call ,a nil value.
The code above is broken.

1. IrrLuaIGUIElement should be a part of "irr.gui", not "irr.scene".
2. Neither the function irr.scene.IrrLuaIGUIElement or irr.gui.IrrLuaIGUIElement exist. The binding is broken and not exporting it. Sorry :(

My job is finally starting to slow down so expect another release of IrrLua within a few weeks.

I've ported IrrLua to Lua 5.1 and also to LuaBinaries. I still need to port over to Irrlicht 1.0 and fix these bugs and then I'll release it.
-------------------------------------
IrrLua - a Lua binding for Irrlicht
http://irrlua.sourceforge.net/
imagination304
Posts: 56
Joined: Mon Jan 09, 2006 2:02 am

Post by imagination304 »

Hi all,

I have no experience of using lua.
Will it slow down frame per second of irrlicht?

Thanks in advance
:)
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Post by zenaku »

imagination304 wrote:Hi all,

I have no experience of using lua.
Will it slow down frame per second of irrlicht?

Thanks in advance
:)

There isn't really a straight answer to that question. It depends on what you are trying to do.

Generally speaking, it will slow down a few frames per second, but not by much.

On my computer:
CDemo.lua (no vsync) - Max FPS == 529
CDemo.exe (no vsync) - Max FPS == 573


If your code uses a lot of callbacks such as shaders, it will slow down much more than that. Things like callbacks should be done in C++ even though you can also do them in Lua.

An irrlicht program usually has a rendering loop at the bottom, e.g. beginScene(); drawAll(); endScene(). In IrrLua, that loop is also implemented in Lua code. If it were implemented in C++ and run from Lua it would perform much faster. I'll probably supply a generic renderLoop() function in IrrLua in a later release that resolves this issue.
-------------------------------------
IrrLua - a Lua binding for Irrlicht
http://irrlua.sourceforge.net/
imagination304
Posts: 56
Joined: Mon Jan 09, 2006 2:02 am

Post by imagination304 »

Hi zenaku

Thank you for your reply.

One more question: what is the difference between vsync and no vsync?

[quote]CDemo.lua (no vsync) - Max FPS == 529
CDemo.exe (no vsync) - Max FPS == 573[/quote]

Thanks in advance
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Post by zenaku »

imagination304 wrote:Hi zenaku

Thank you for your reply.

One more question: what is the difference between vsync and no vsync?
CDemo.lua (no vsync) - Max FPS == 529
CDemo.exe (no vsync) - Max FPS == 573
Thanks in advance
Uhm, when you run the demo, it's one of the options :) If you use vsync, the framerate doesn't change so you can't benchmark.
-------------------------------------
IrrLua - a Lua binding for Irrlicht
http://irrlua.sourceforge.net/
Post Reply