-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow lua 5.4 import #156
Comments
I can not find the import feature you mentioned in official doc http://www.lua.org/manual/5.4/. Can you provide a link or something to get me informed? |
Fair point, perhaps I was mistaken. Playdate's embedded Lua only uses the |
"import" is treated as a keyword for the moment, but I can try to change that. And supporting 'import("module")' as a function call in Yuescript. |
Would a macro suffice here? export macro raw = (code) ->
{ :code, type: "lua" }
-- usage
$raw [[ import "x" ]] This is what I do since $raw[[
import("core.base.option")
]] |
@chrsm Macros would work, but what about import from and import as? |
I'd say that import "foo" still compiles to local foo = require("foo") but foo = import "foo" becomes local foo = import("foo") If someone wanted to make the global require = import at the beginning of their script. |
Digging around the parser rules a little while, I'm thinking of adding special aliasing syntax like: `import "abc" -- the backtick will turn keyword import to variable name Or we have to keep using macro function like this to get similar result: macro import = (moduleName) -> "_G['import'](#{moduleName})"
$import "abc.zyx"
mod = $import "module"
nil compiles to: _G['import']("abc.zyx")
local mod = _G['import']("module")
return nil Making And an alternative writing could be just: abc = _G.import "abc"
_G.import "module" |
If you want to use the macro Playdate = (moduleName) -> "_G.import(#{moduleName})"
from $Playdate("module") import a, b, c get local a, b, c
do
local _obj_0 = _G.import("module")
a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
end
|
Lua 5.4 uses
import
instead ofrequire
. Is there a way we can useimport "module"
instead ofrequire("module")
in generated code?The text was updated successfully, but these errors were encountered: