From bf92daa5d47cfa6379cfe5e1ce80533e92b4f6cc Mon Sep 17 00:00:00 2001 From: Antoine Cellerier Date: Sun, 28 Feb 2010 00:39:53 +0100 Subject: [PATCH] Add error handling to luac intf. --- share/lua/intf/luac.lua | 45 +++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/share/lua/intf/luac.lua b/share/lua/intf/luac.lua index 9cb39cad9b..4c6beb5df2 100644 --- a/share/lua/intf/luac.lua +++ b/share/lua/intf/luac.lua @@ -1,7 +1,7 @@ --[==========================================================================[ luac.lua: lua compilation module for VLC (duplicates luac) --[==========================================================================[ - Copyright (C) 2010 the VideoLAN team + Copyright (C) 2010 Antoine Cellerier $Id$ Authors: Antoine Cellerier @@ -22,27 +22,46 @@ --]==========================================================================] usage = -[[ To compile a lua script to luac run: - vlc -I lua --lua-intf --lua-config 'luac={input="file.lua",output="file.luac"}' +[[ +To compile a lua script to bytecode (luac) run: + vlc -I lua --lua-intf --lua-config 'luac={input="file.lua",output="file.luac"}' +Output will be similar to that of the luac command line tool provided with lua with the following arguments: + luac -o file.luac file.lua ]] require "string" require "io" -vlc.msg.info("About to compile lua file") -vlc.msg.info(" Input is '"..tostring(config.input).."'") -vlc.msg.info(" Output is '"..tostring(config.output).."'") +function compile() + vlc.msg.info("About to compile lua file") + vlc.msg.info(" Input is '"..tostring(config.input).."'") + vlc.msg.info(" Output is '"..tostring(config.output).."'") + if not config.input or not config.output then + vlc.msg.err("Input and output config options must be set") + return false + end + + local bytecode, msg = loadfile(config.input) + if not bytecode then + vlc.msg.err("Error while loading file '"..config.input.."': "..msg) + return false + end + + local output, msg = io.open(config.output, "wb") + if not output then + vlc.msg.err("Error while opening file '"..config.output.."' for output: "..msg) + return false + else + output:write(string.dump(bytecode)) + return true + end +end -if not config.input or not config.output then - vlc.msg.err("Input and output config options must be set") + +if not compile() then for line in string.gmatch(usage,"([^\n]+)\n*") do vlc.msg.err(line) end -else - local bytecode = loadfile(config.input) - local output = io.open(config.output, "wb") - output:write(string.dump(bytecode)) end - vlc.misc.quit() -- 2.39.5