--****************************************************************************** --* * --* File: LuaJava.lua Revision: 1.0 * --* * --* Contents: Lua-part of the author's runtime environment for LuaJava * --* * --* Creation: 07.11.2004 Last Modification: 07.11.2004 * --* * --* Environment: Lua 5.0, LuaJava 1.0b3, Java 1.4.2 * --* * --* Author: Andreas Rozek Phone: ++49 (7031) 222305 * --* Bunsenstraße 80/1 Fax: - * --* D-71032 Böblingen EMail: Info@Andreas-Rozek.De * --* Germany * --* * --* URL: http://www.Andreas-Rozek.de/ * --* * --* Copyright: the software is published under the "GNU Lesser General Pub- * --* lic License" (see "http://www.fsf.org/copyleft/lesser.html" * --* for additional information) * --* * --* Comments: this script basically defines a new version of the built-in * --* "require" function (plus everything needed for "require") * --* and then loads everything else from separate script files * --* * --****************************************************************************** -------------------------------------------------------------------------------- -- io.getFolderSeparator determines the platform-specific separator character -- -------------------------------------------------------------------------------- local FileClass = luajava.bindClass("java.io.File"); function io.getFolderSeparator () return FileClass.separator; end; io.FolderSeparator = io.getFolderSeparator(); -- shortcut for direct access -------------------------------------------------------------------------------- -- require an updated version of the intrinsic "require" function -- -------------------------------------------------------------------------------- local _require = require; -- preserve the original function function require (PackageName) -- and define a better one if (PackageName == nil) then error("missingArgument: no \"PackageName\" given"); end; if (type(PackageName) ~= "string") then error("illegalArgument: given \"PackageName\" is not of type \"string\""); end; PackageName = string._trim(PackageName); -- normalize the package name a bit if (PackageName == "") then error("emptyArgument: given \"PackageName\" is empty"); end; if (io.FolderSeparator ~= "/") then PackageName = string.gsub(PackageName, "/", io.FolderSeparator); end; --**** check if that package is currently being loaded **** if (_LOADING ~= nil) and (type(_LOADING) == "table") and _LOADING[PackageName] then return true; -- avoid recursive loading of the requested package else if (_LOADING == nil) or (type(_LOADING) ~= "table") then _LOADING = {[PackageName] = true}; -- mark package as being loaded else _LOADING[PackageName] = true; end; _require(PackageName); if (_LOADING ~= nil) and (type(_LOADING) == "table") then _LOADING[PackageName] = nil; -- unmark package end; end; end; -------------------------------------------------------------------------------- -- string._trim yields a copy of "Argument" without leading/trailing blanks -- -------------------------------------------------------------------------------- function string._trim (Argument) return string.gsub(string.gsub(Argument, "^%s+", ""), "%s+$", ""); end; --****************************************************************************** --* * --* now load any additional libraries * --* * --****************************************************************************** require("luna/Common"); -- commonly used constants and functions require("luna/data/IO"); -- extensions for Lua's intrinsic libraries require("luna/data/Math"); require("luna/data/OS"); require("luna/data/String"); require("luna/data/Table");