-
Notifications
You must be signed in to change notification settings - Fork 305
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
add custom extension support for importing source file #350
Conversation
Thanks for the PR. I will have to look at the code later tonight, but can we change the function signature to something like: SetImportFileExt(...string) and it should replace the entire array instead of appending. |
ok. - func (c *Compiler) SetImportExt(ext string) {
+ func (c *Compiler) SetImportFileExt(exts ...string) {
roger roger. ( ̄^ ̄)ゞ |
I wonder if we have to document it but couldn't determine where. Is the godoc enough? |
we don't have documentation for that particular function, but maybe we can add a small note somewhere under here https://github.com/d5/tengo/blob/master/docs/tutorial.md#modules? |
LGTM. Looks much better overall |
This PR features issue #286 by implementing
tengo.Compiler.SetImportFileExt()
method which allows specifying custom extension names.This feature aims for "
tengo
" as a library usage and should not affect the "/cmd/tengo" itself.func main(){ ... c := tengo.NewCompiler(srcFile, nil, nil, modules, nil) c.EnableFileImport(true) c.SetImportDir(filepath.Dir(pathFileSource)) + err := c.SetImportFileExt(".tengo", ".mshk") // It will search *.tengo and *.mshk script files ... }
c.SetImportExt(".mshk")
searched for both*.tengo
and*.mshk
(*.tengo
by default) with no input validation.But currently it needs to explicitly define as
c.SetImportFileExt(".tengo", ".mshk")
for both file extensions. And returns an error if any given args are invalid as well.