Skip to content
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

[Feature Request] Easier imports #164

Open
clsource opened this issue Nov 28, 2024 · 0 comments
Open

[Feature Request] Easier imports #164

clsource opened this issue Nov 28, 2024 · 0 comments

Comments

@clsource
Copy link
Contributor

clsource commented Nov 28, 2024

Using the following project structure

SlothCreator
├── .editorconfig
├── lib
│   ├── Generators
│   │   └── sloth_generator.onyx
│   └── Sloth
│       ├── activity.onyx
│       ├── color.onyx
│       ├── food.onyx
│       ├── habitat.onyx
│       ├── power.onyx
│       ├── schedule.onyx
│       └── sloth.onyx
├── onyx-pkg.kdl
└── project.onyx

onyx-pkg.kdl

package {
    name "Sloth Creator"
    author "clsource"
    url ""
    description "A package for your Sloth needs"
    version "1.0.0"
}

config {
    dependency_source_path "./deps"
    dependency_binary_path "./bin"
}

project.onyx

package main

#load_all "lib/Sloth"
#load_all "lib/Generators"

use Sloth
use Generators

use core

main :: () {
    habitat := Sloth.init_habitat(is_humid = true, is_warm = true)
    sloth := Generators.generate_sloth(habitat)
    sloth.energy_level = Sloth.sloth_eat(sloth, Sloth.DefaultFoodType.Large_Leaf)
    core.printf("sloth: {} | energy: {} | power: {} ¡ color: {}", sloth.name, sloth.energy_level, sloth.power, sloth.color)
}

It would be awesome if we could have an import/require keyword that can simplify the code.

import

Will load the package from the path and use it.

import "lib/Sloth"

Would be the same as

#load_all "lib/Sloth"
use Sloth

And an alias can be done like

import MySloth "lib/Sloth"

would be the same as

#load_all "lib/Sloth"
use Sloth { MySloth :: package }

require

Will load the package from the path and use all the procedures.

require "lib/Sloth"

would be the same as

#load_all "lib/Sloth"
use Sloth {package, * }

Maybe can also call a macro procedure like Elixir's __using__

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant