Skip to content

triggers from delegate with bound args - fixes #2236#2238

Merged
Dunbaratu merged 1 commit intodevelopfrom
unknown repository
Mar 12, 2018
Merged

triggers from delegate with bound args - fixes #2236#2238
Dunbaratu merged 1 commit intodevelopfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Mar 5, 2018

I have chosen to fix CPU.AddTrigger because this seems to be the point where UserDelegate gets converted to EntryPoint and PreBoundArgs were lost. Now passes the test with simple button:

local wnd is gui(0).
local btn is wnd:addButton("TEST").
local function click {
	parameter text.
	print text.
}
set btn:onClick to click@:bind("TEST").
wnd:show().

fixes #2236

P.S.: I seem to have different formatting options. Would it be possible to add .editorconfig?

@ghost
Copy link
Author

ghost commented Mar 10, 2018

Would it be possible to add .editorconfig maybe like this?

[*.cs]
indent_style = space
indent_size = 4
charset = utf-8
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_method_call_parameter_list_parentheses = false

or whatever you prefer (I prefer tabs - ts=4, or two spaces. Four spaces are a bit odd, but use whatever you like, that .editorconfig should make it easier for anybody using VS or anything supporting it and I made it according to what the current style appears to be).

..and add .vs/ to .gitignore
Thank you

@Dunbaratu
Copy link
Member

Dunbaratu commented Mar 11, 2018

I'm about to test this PR and probably merge it, but as for the visual studio settings, that would be a better question for @hvacengi than me. I don't use Visual Studio so I can't really verify what those settings do.

But one thing I am slightly wary of: the terminology "ts=4" implies you might be using vim. Is this true? I use it too sometimes. If you are using vim, I would strongly recommend indenting with sw=4 rather than ts=4, (leaving it at ts=8, the standard default), and setting expandtab on, and using control-T to indent rather than the tab key. The effect of using ts=4 and the tab key to indent is to embed actual ascii tab chars into the source code, but do so at the wrong size of 4, which then makes the lines look all mangled when someone else views them in another program that uses the standard setting of 8 (or posts snippets to a text paste website, etc - any viewer of the file that isn't the IDE).

@Dunbaratu
Copy link
Member

This PR seems like a good solution. Good work, @firda-cze. Ideally, it would probably be better to fix TriggerInfo so it is capable of understanding all the information about a delegate (including its bound args) rather than only knowing the entry point and args.

But given the limitation that TriggerInfo doesn't have that information, this is the best way to do it.

@Dunbaratu Dunbaratu merged commit 02ef49b into KSP-KOS:develop Mar 12, 2018
@Dunbaratu
Copy link
Member

Merged, but first I had to strip some hard tab chars and replace them with equivalent spaces to match our standard. The assumption that you are viewing the ascii text in a system that uses 4-char tabs isn't something you can always do in every tool you might use with the source code (especially as 8 char tabs is the more common standard). If someone else views the code in a viewer with different tab sizes than you used, it looks all wrong to them as the tabbed lines don't match up with the spaced lines. That's why tabs have to be a sort of all-or-nothing affair in the source code from day 1. Either you have to say it's wrong to use tabs, or say it's wrong to use spaces. You can't really mix and match the two styles in the same project.

@Dunbaratu
Copy link
Member

@firda-cze I delayed merging this a while because I was investigating a problem with delegates that showed up when I ran kerboscript_tests/delegatetest6.ks after merging this - but on further inspection that problem pre-dates your PR and had nothing to do with it - it happens even when I back out your PR, so it shouldn't prevent your PR. (There seems to be some memory that's not orphaning properly in closures once the program ends and the closure is thrown away. But given how indirect managed memory systems' relationship with the actual OS memory footprint of the process is, it's a royal PITA to tell if the problem is "real" or not.)

@ghost
Copy link
Author

ghost commented Mar 12, 2018

@Dunbaratu I also use vim, but you can add ?ts=4 to any github url and you will see four spaces where tabs are.
I have noticed you use spaces (after pushing, didn't notice that in editor) and that was the reason I suggested using .editorconfig. I will not change my global VS settings, because that would break a lot of my projects, but that .editorconfig (especially the first three lines) will force spaces for KOS (or any solution/project having it).

And debate about what is best can be endless and pointless, so, I will only state my own opinion: four tabs are best for coding, it is just faster for navigation, easier and faster editing. But I can understand that some editors have problems with it, so, I accept two spaces as reasonable alternative (those two are mainstream, ts=4 or sw=2). Four spaces are cumbersome for me, but I can use it if you add the .editorconfig (and I added it for myself for future edits not to break your tabs/spaces).

@ghost ghost deleted the trigger-bind branch March 13, 2018 14:52
@ghost
Copy link
Author

ghost commented Mar 15, 2018

@Dunbaratu The problem with kerboscript_tests/delegatetest6.ks is probably not real. The memory drops when I force GC.Collect() in my tester, stacks are empty, it only appears to be the lack of full collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(GUI) triggers do not work with delegate with bound args

3 participants