Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8180331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:11:28+00:00 2026-06-07T00:11:28+00:00

I am using vala. This is the source code that gives that compile time

  • 0

I am using vala.
This is the source code that gives that compile time bug :

private Gee.HashMap<string,VoidFunc> fill_actions()
{
    var actions = new Gee.HashMap<string,VoidFunc>();
    MainWindow win = window;
    actions["t"] = () => _puts(win.title);
    return actions;
}

First I tried to access this.window directly but that gave another error so I tried this with a local scope variable.

Error when doing directly this.window :

This access invalid outside of instance methods
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:11:29+00:00Added an answer on June 7, 2026 at 12:11 am

    It sounds like VoidFunc is declared with [CCode (has_target = false)]. What that means is that no context information is passed to it, and AFAIK that is the only way delegates work as generic type arguments. The reason for this is limitations in C, so assuming VoidFunc looks like this:

    [CCode (has_target = false)]
    public delegate void VoidFunc ();
    

    What you’ll get in C is something like this:

    typedef void (*VoidFunc)();
    

    As opposed to something like this if you didn’t have the [CCode (has_target = false)]:

    typedef void (*VoidFunc)(gpointer user_data);
    

    When you pass around callbacks in C you generally do so with between one and three arguments. Something with all three would look like this:

    void foo (VoidFunc void_func, gpointer user_data, GDestroyNotify notify);
    

    The first parameter is the actual function. The second parameter is the value to pass as user_data to the callback, and is what Vala uses to pass context information to the callback (which is what allows it to act as an instance method, or even a closure). The third parameter is used to specify a function to free user_data when it is no longer needed.

    What [CCode (has_target = false)] means is that the delegate doesn’t have a user_data argument, and therefore cannot be used as a closure or instance method.

    The reason this is necessary with a generic argument is that generics look something like this at the C level:

    void foo_bar (gpointer data, GDestroyNotify notify);
    

    The first parameter is the data that you want to use as a generic value, the second is actually only added if the generic argument is owned (as it is in the case of the set methods in Gee), and is called with user_data as an argument when user_data is no longer needed.

    As you can see, when trying to use a delegate as a generic, there is nowhere to put the user_data argument, which is why Vala only allows delegates without targets to be generic arguments.

    The solution is basically to wrap the delegate in a class:

    public delegate void VoidFunc ();
    
    public class YourClass {
      private class VoidFuncData {
        public VoidFunc func;
    
        public VoidFuncData (owned VoidFunc func) {
          this.func = (owned) func;
        }
      }
    
      private Gee.HashMap<string,VoidFuncData> fill_actions() {
        var actions = new Gee.HashMap<string,VoidFuncData>();
        string win = "win";
        actions["t"] = new VoidFuncData (() => GLib.debug (win));
        return actions;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this piece of code: using Posix; int fuseguifs_getattr(string path, Posix.Stat *stbuf) {
I'm currently writing an application using Vala that requires me to send data over
Using CI for the first time and i'm smashing my head with this seemingly
Using import datetime in python, is it possible to take a formatted time/date string
I've got a string: doCall(valA, val.valB); Using a regex in GVIM I would like
In the external code that I am using there is enum: enum En {VALUE_A,
Using DMD 2.057, I cannot get the following code to compile: import std.stdio; import
Using a populated Table Type as the source for a TSQL-Merge. I want to
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
I am trying to create python bindings to a vala library using the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.