Detecting Global Variables Call

Hello everyone !

For my current development (GithubLoader), i want simplify the system for never directly write tab order of a “package”. For do that, i need a function who search undefined global var call for sort files.
For the moment, i just check the simple case with inheritance.

I’ve read this article : and all solutions needs a library.

If anybody have a better idea ^^

I am not sure i understand your problem. It seems to be ‘tab order management’, is this correct? To manage this i simply name my tabs t10_blabla, t20_blablabla etc… So they are atomatically load in the good order. Might not be your question, though…

This is my question, but i find touch name of tab is a “bad” way to manage order in a big project. Because i made my project directly on github, with directory, sub-directory, etc…

So if i understand your needs, i summarize:

  • tabs are in individual files under github.
  • in various directories.
  • you want to download in the right order and run the necessary tabs into codea to run your new project depending on them.
    So maybe:
    -each tab is known vis its github adress, let call it the tab ‘key’.
  • When you load and run a tab, indicate in a global table that this tab has been loaded: loaded[key]=true.
  • at the beginning of each tab, list the tabs needed first, in correct order, and load then if not already loaded.
    Just a 0.02€ idea…

You’r right for the problem, but my goal is to dodge write more code…

So you want to write a single function that will:

  • dowload alll the tabs.
  • sort them in the right order.
  • run the tabs in this order.
  • just from the already written code.
    The only real problem is: how to sort the tabs? Why not:
  • search all the class definition in each tab, put them in a table (indexed by the tab key).
  • iterate over the table to list all the classes and sub classses used by the tab.
  • sort this table by ‘if i contain a class call to you, i am after you’ (rule is more tricky than that).
    You problem is then a string search problem and tab ordering, for which you have all the tools needed. But maybe this view is too simple.

@HyroVitalyProtago My dynamic tab loader may help you here, it allows you to load in a tab or tabs to the global table or a local so you would effectivly specify the tab order by “importing” tabs into _G or a local (which id recommend over the global table). It only ever loads a file once and isolates them into their own area for their project. So it maybe a good starting point for your needs i hope :slight_smile:

@Jmv38 This is what a talk in the first post, search class inheritance is simple and already do but i think about other global vars.

Good exemple : Project Cargo Bot

Tab ABCMusic contain the ABCMusic class,

Tab Music contain ABCMusic:percentageCached() (strange location of code but possible)

how find the global var call to ABCMusic ? And this is a specific case, but how to find all cases ?

@XanDDemoX This is a solution, like in other programming language but i think we are able to do better in this case.

Maybe i’m too perfectionist… and especially slacker for add import in all my tab x)

@HyroVitalyProtago Perhaps but perfectionism is an excellent trait for a developer :wink:

In my honest opinion what your attempting is an extremely complex problem. A couple of (perhaps slightly rhetorical) questions need to be asked :slight_smile: why do we as developers set the tab order in Codea rather than Codea resolve this for us and we can just use any tab? and why do other languages use explicit declaration and rather than entirely implicit. (although implicit is permitted after “imports” in a number of languages)?

You have a number of issues to resolve when considering something like this, here’s just a few. Resolving the references effectively “just in time” (this is an entire topic in itself), what if you have clashing references where both are required (which you can resolve by name-spacing), what if one doesn’t exist and what happens with dynamically created objects. Then there’s probably the largest of them all how do you make it efficient?

So without wanting to make this sound like a sales pitch :slight_smile: a few one liners here and there may save you a lot of headaches :slight_smile: Did i mention it can do an entire project in one line too (or perhaps package in your case :wink: ).

This is because that’s a complex problem that i ask to the codea community ^^ And maybe, one person have act of genius for resolve it =)

For my current project, i think class inheritance is sufficient. But for next updates, and especially my intellect, it could be great to resolve it. ^^

Start with a list of the tabs (you must have it to load them).
Load each tab in a string.
(1) for each tab in the list.
Execute it with pcall and loadstring.
If execute fail, this is because missing class or global var (check for globVar == nil if the tab assumes globVar already exist, throw an error if not).
If no failure remove he tab from the list.
At the end of list, if list not empty start again at (1).
When the list is empty, all tabs have loaded correctly.
If you dont make too much cross-nested constructs, this should work.

Yeah ! i’v totally forgot the pcall function, thanks a lot @Jmv38 :wink: