You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One thing that's nice about Lua is it's very simplistic module system. Basically, each file is treated like a function, and can return any arbitrary value as a result:
However, I see a few problems with this. The most important one is that libraries need to implement weird hacks to get relative requires, which is not ideal. Ruby solves this by having a separate require_relative, but I think it looks quite ugly.
The basics: require in Mica
require would work the same way it does in Lua. The value returned by the module is also returned by require.
# my_module.mi
impl struct MyModule # see #54
func hello()
print("yo!")
end
end
MyModule
Unlike Lua however, require works more like in Node.js, where paths use / as a path separator, and if a path doesn't start with . or .., a system module is loaded. System modules are provided by the standard library and host application; for instance, NetCanv could register a module netcanv.
netcanv = require("netcanv") # require a system module
brush = require("netcanv/brush") # system modules can have submodules
util = require("./util") # require a local module
The text was updated successfully, but these errors were encountered:
One thing that's nice about Lua is it's very simplistic module system. Basically, each file is treated like a function, and can return any arbitrary value as a result:
Then, one can import the module by using the
require
function, which searches for modules relative to the main module.However, I see a few problems with this. The most important one is that libraries need to implement weird hacks to get relative
require
s, which is not ideal. Ruby solves this by having a separaterequire_relative
, but I think it looks quite ugly.The basics:
require
in Micarequire
would work the same way it does in Lua. The value returned by the module is also returned byrequire
.Unlike Lua however,
require
works more like in Node.js, where paths use/
as a path separator, and if a path doesn't start with.
or..
, a system module is loaded. System modules are provided by the standard library and host application; for instance, NetCanv could register a modulenetcanv
.The text was updated successfully, but these errors were encountered: