Changeset 69f74c2 for perlglue.xs


Ignore:
Timestamp:
Feb 19, 2013, 8:29:34 PM (9 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master
Children:
3b9ca71
Parents:
e5210c9
git-author:
David Benjamin <davidben@mit.edu> (06/09/12 23:05:48)
git-committer:
David Benjamin <davidben@mit.edu> (02/19/13 20:29:34)
Message:
And now... the moment you've all been waiting for...

Expose OWL_VARIABLE_OTHER variables to perl. Rewrite all perl variable
entry points to use that one. From now on, C only thinks of these
variables as strings.

(This has one regression to be fixed in a later commit: you can't
set/unset with no arguments since we don't know how to set from
boolean.)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perlglue.xs

    r353719a r69f74c2  
    405405MODULE = BarnOwl                PACKAGE = BarnOwl::Internal
    406406
    407 /* TODO: Revise this after churn is done.
    408 void
    409 new_variable_full(name, summary, desc, type, data, default_val, get_fn, get_default_fn, tostring_fn, validate_fn, set_fn, fromstring_fn)
     407void
     408new_variable(name, summary, description, validsettings, get_tostring_fn, set_fromstring_fn, data)
    410409    const char *name
    411410    const char *summary
    412     const char *desc
    413     int type
     411    const char *description
     412    const char *validsettings
     413    SV *get_tostring_fn
     414    SV *set_fromstring_fn
    414415    SV *data
    415     SV *default_val
    416     SV *get_fn
    417     SV *get_default_fn
    418     SV *tostring_fn
    419     SV *validate_fn
    420     SV *set_fn
    421     SV *fromstring_fn
    422416    CODE:
    423417{
    424         owl_variable *variable = NULL;
    425         int count = 0;
    426         int res = -1;
    427         GClosure *delete_fn = NULL;
    428         if(!SV_IS_CODEREF(get_fn)) {
    429                 croak("Get function must be a coderef!");
    430         }
    431         if(!SV_IS_CODEREF(tostring_fn)) {
     418        /* data is somewhat redundant given we can create closures, but oh
     419         * well. Might be convenient sometimes. */
     420        if(!SV_IS_CODEREF(get_tostring_fn)) {
    432421                croak("To-string function must be a coderef!");
    433422        }
    434         if(!SV_IS_CODEREF(validate_fn)) {
    435                 croak("Validation function must be a coderef!");
    436         }
    437         if(!SV_IS_CODEREF(set_fn)) {
    438                 croak("Set function must be a coderef!");
    439         }
    440         if(!SV_IS_CODEREF(fromstring_fn)) {
     423        if(!SV_IS_CODEREF(set_fromstring_fn)) {
    441424                croak("From-string function must be a coderef!");
    442425        }
    443         if(!SV_IS_CODEREF(get_default_fn)) {
    444                 croak("Get-default function must be a coderef!");
    445         }
    446         variable = owl_variable_newvar(name, summary, desc);
    447         variable->type = type;
    448         variable->get_fn = perl_closure_new(get_fn, data, false);
    449         variable->get_tostring_fn = perl_closure_new(tostring_fn, data, false);
    450         variable->validate_fn = perl_closure_new(validate_fn, data, false);
    451         variable->set_fn = perl_closure_new(set_fn, data, false);
    452         variable->set_fromstring_fn = perl_closure_new(set_fn, data, false);
    453         variable->get_default_fn = perl_closure_new(get_default_fn,
    454                                                     data, false);
    455         delete_fn = g_cclosure_new(G_CALLBACK(owl_perl_delete_perl_variable),
    456                                            data, NULL);
    457         g_closure_set_marshal(delete_fn,g_cclosure_marshal_VOID__VOID);
    458         g_closure_ref(delete_fn);
    459         g_closure_sink(delete_fn);
    460         variable->delete_fn = delete_fn;
    461 
    462         SvREFCNT_inc(data);
    463 
    464         PUSHMARK(SP);
    465         XPUSHs(sv_2mortal(newSViv(PTR2IV(variable))));
    466         XPUSHs(default_val);
    467         XPUSHs(data);
    468         PUTBACK;
    469         count = call_sv(set_fn, G_SCALAR | G_EVAL);
    470         SPAGAIN;
    471        
    472         res = POPi;
    473         owl_dict_insert_element(owl_global_get_vardict(&g),
    474                                 variable->name, variable, NULL);
    475         PUTBACK;
     426
     427        owl_variable_dict_newvar_other(owl_global_get_vardict(&g),
     428                                       name, summary, description, validsettings,
     429                                       perl_closure_new(get_tostring_fn, data, false),
     430                                       perl_closure_new(set_fromstring_fn, data, false));
    476431}
    477 */
    478 
    479 void
    480 new_variable_string(name, ival, summ, desc)
    481         const char * name
    482         const char * ival
    483         const char * summ
    484         const char * desc
    485         CODE:
    486         owl_variable_dict_newvar_string(owl_global_get_vardict(&g),
    487                                         name,
    488                                         summ,
    489                                         desc,
    490                                         ival);
    491 
    492 void
    493 new_variable_int(name, ival, summ, desc)
    494         const char * name
    495         int ival
    496         const char * summ
    497         const char * desc
    498         CODE:
    499         owl_variable_dict_newvar_int(owl_global_get_vardict(&g),
    500                                      name,
    501                                      summ,
    502                                      desc,
    503                                      ival);
    504 
    505 void
    506 new_variable_bool(name, ival, summ, desc)
    507         const char * name
    508         int ival
    509         const char * summ
    510         const char * desc
    511         CODE:
    512         owl_variable_dict_newvar_bool(owl_global_get_vardict(&g),
    513                                       name,
    514                                       summ,
    515                                       desc,
    516                                       ival);
    517432
    518433void
Note: See TracChangeset for help on using the changeset viewer.