require("文件地址")web
在apollox物理设计上,支持lua的require模块方式,require方法能够在web模式和tool方式使用。 本文简单介绍一下,在web模式下的配合vfs的使用。测试
require的具体细节和lua的实现方式相似, 模块做为程序的最小单元存在,模块与模块之间的关系,应该是隔离的。 在web模式下使用vfs组织模块查找的路径。ui
使用require在某种状况下会有限制,他们分别是若是模块的语法存在错误,将没法交织到模块的代码抛出错误。 若是vfs里并无该模块的平坦模式的代码, 会抛出错误。若是vfs配置了baseURL,通常vfs在内存没法查找到该文件将会根据baseURL的路径进行远程加载该模块。lua
一个简单示例的vfs的视图设计
--请注意这个代码在web console示例程序中是没法执行的。 --这是一个lua的new模块,module case 里使用 local m = {} local hellow = function () print("hellow, i am a module method"); end m.hellow = hellow; return m;
--请注意这个代码在web console示例程序中是没法执行的。 --这是一个lua的new模块,module case 里使用 local other = require("build/lua_module.lua") local m = {} local hellow = function () print("hellow, i am duplicate def"); end m.hellow = hellow; m.other = other.hellow; return m;
////////// /// 模块测试 ///////// var module = require("build/lua_module.lua"); if(module) { module.hellow(); } var module2 = require("build/lua_duplicatedef.lua"); if(module) { module2.hellow(); module2.other(); }