Open KCreate opened 7 years ago
@KCreate I would like to make them easier to access. An extra variable for that is to much. Maybe a special shortcut for that?
What would you propose?
Maybe that a Namespace has the same syntax as accessing an class or module in Crystal?
So charly_namespace
should automatically inject itself into the program? That would cause a namespace conflict pretty fast. Having the ability to put each namespace and method into a user-defined variable makes more sense imho.
What is possible however is, that __internal__namespace
could return a class instead of an object, allowing multiple instances of internals namespaces.
charly_namespace "mynamespace" do
charly_api "constructor" do
puts "initializing"
end
charly_api "greet" do
TString.new "Hello world"
end
charly_api "goodbye" do
TString.new "Bye world"
end
end
const MyNamespace = __internal__namespace("mynamespace")
const MyObject = MyNamespace() // prints "initializing"
MyObject.greet() // => "Hello world"
MyObject.goodbye() // => "Bye world"
But then we'd need to add some methods which can operate on the classes instance and static variables.
What are your thoughts on this?
I think that would work great.
You should be able to put methods added via native extensions into a namespace.
Access inside charly:
The interpreter will automatically create bindings to all these methods.