SnowfeetEngine icon indicating copy to clipboard operation
SnowfeetEngine copied to clipboard

Cannot inherit class defined in another file

Open Zylann opened this issue 10 years ago • 0 comments

Due to "random" compilation order, inheriting a class defined in another file can fail. There should be a require() function like Lua that compiles a dependency file before the current one.

Alternatively this problem wouldn't exist if classes were evaluated afterwards, like function bodies:

class("MyClass", "InheritedClass", { // body })

But that's an ugly syntax and I don't know how it would be possible to define classes in Squirrel like that without giving up the class system...

EDIT: I think I won't add a require() function, because it just has to do with file execution order. Also, when scripts are precompiled as a single binary, it makes no sense to require("file.nut") at code execution time. So I prefer implement it with the script preprocessor: #require "MyFile.nut".

require would not execute the file, but just declare that it depends on another, so the script loader will be able to calculate the order at compile time.

Zylann avatar Nov 17 '15 01:11 Zylann