This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
HDeffo's profile picture

Detect what types a function expects

Started by HDeffo, 06 April 2015 - 09:19 PM
HDeffo #1
Posted 06 April 2015 - 11:19 PM
So currently I am working in a drag and drop style tree chart program editor for ComputerCraft. I would like to have it fully support custom APIs and detect what variable types should be placed into them in as efficient a method as possible. Currently I'm working with creating a coroutine that rapidly calls the function passing random variable types to see if any attempts don't error out. It can already catch number of arguments needed or unknown number (… In function)


I really don't believe this is possible in any realistic method but I figured maybe someone here can think outside the box enough and give me some ideas. It doesn't need to be a perfect science just a close estimate that's correct at least half the time and I'll just add an easy override for the user to plug anything they want into the box.
Wojbie #2
Posted 06 April 2015 - 11:34 PM
I can think of so many things that blind calling a function can do wrong. as for estimating what function needs? Can't think of a way. How about program asking user what function it don't know requires using some kind of setup wizard and remembering what they choose? With an easy override for the user to plug anything they want into the box
Bomb Bloke #3
Posted 07 April 2015 - 10:14 AM
If I wanted to do something like this, I guess I'd trawl through the actual APIs folder and parse the source directly. Check how many arguments each function expects, then read on further to see what sort of operations are used on them. The catch is that some API functions don't have Lua source available (eg, most of the "turtle" API).

Although he doesn't always do it, and few other coders around here do it at all, Dan often prefixes his variable names with a lowercase character indicating their type.
Lupus590 #4
Posted 07 April 2015 - 12:24 PM
for things like the turtle API, they are coded on the java side, which means that you can't change them, which means that you could hard code the function argument thing
HDeffo #5
Posted 07 April 2015 - 12:25 PM
I honestly didn't think about that compiling how it runs the function DUH thanks bomb bloke :P/>

if the function asks for "sText, second, var" and somewhere in the code it does second=second-1 and somewhere it does table.concat(var) we can figure out what variables it needs. This actually looks possible now.