nojanath / SublimeKSP

Fork of Nils Liberg's SublimeKSP plugin. See README for details.
GNU General Public License v3.0
86 stars 18 forks source link

Issue with inlined function calling a taskfunc with an argument #97

Open ghost opened 6 years ago

ghost commented 6 years ago

Some code should explain it better:

function ks_function
    tcm_function(1)
end function

taskfunc tcm_function(param)
    message(param)
end taskfunc

on init
    tcm.init(10)
    declare ui_switch switch
end on

on ui_control(switch)
    ks_function
end on

Compile error: _wrong number of parameters to tcmfunction. Expected 1, got 0 works if you 'call' ks_function. Works if the functions are declared after 'on init' and after 'on ui_control(switch). So why not do that? Because it's a bit messy and it might affect larger projects.

mkruselj commented 6 years ago

I think tcm.init() needs to be defined in ICB before a taskfunc is defined, so what you did above is throwing the compiler off.

By the way, you should be using a macro in your example rather than a function (for ks_function). Then it works.

eitherys commented 4 years ago

Technically, this should not create an error. I will leave this issue open; in the meantime, I recommend always including functions after the init callback. We manage a lot of large projects and this isn't an issue for us, the main idea is to create a "build file" that assembles all your callbacks and functions as imported macros from other imported files. This lets you write code the way you desire in other files, while assembling it in a more standard order for the compilation order.

To clarify, this is now possible, because tcm.init() was just improved in the latest versions of SublimeKSP to support tcm.init() in imported files.