~ubuntu-branches/ubuntu/oneiric/swig1.3/oneiric

« back to all changes in this revision

Viewing changes to Source/Modules/lua.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-11-10 16:29:56 UTC
  • mfrom: (1.2.8 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20081110162956-xue6itkuqhbza87s
Tags: 1.3.36-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop pike and libchicken-dev from the build-depends 
    (both are universe)
  - Use python2.5 instead of python2.4.
  - use php5
  - Clean Runtime/ as well.
  - debian/Rules (clean): Remove Lib/ocaml/swigp4.ml.
  - drop "--without-mzscheme", we don't have it in our build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
*/
42
42
 
43
 
char cvsroot_lua_cxx[] = "$Id: lua.cxx 10326 2008-03-27 01:58:30Z mgossage $";
 
43
char cvsroot_lua_cxx[] = "$Id: lua.cxx 10540 2008-06-21 15:23:02Z wsfulton $";
44
44
 
45
45
#include "swigmod.h"
46
46
 
51
51
*/
52
52
#define REPORT(T,D)             // no info:
53
53
//#define REPORT(T,D)   {Printf(stdout,T"\n");} // only title
 
54
//#define REPORT(T,D)           {Printf(stdout,T" %p\n",n);} // title & pointer
54
55
//#define REPORT(T,D)   {Printf(stdout,T"\n");display_mapping(D);}      // the works
55
56
//#define REPORT(T,D)   {Printf(stdout,T"\n");if(D)Swig_print_node(D);}      // the works
56
57
 
333
334
   * --------------------------------------------------------------------- */
334
335
 
335
336
  virtual int functionWrapper(Node *n) {
336
 
    //    REPORT("functionWrapper",n);
 
337
    REPORT("functionWrapper",n);
337
338
 
338
339
    String *name = Getattr(n, "name");
339
340
    String *iname = Getattr(n, "sym:name");
361
362
        we need to add a couple of local variables
362
363
    NEW LANGUAGE NOTE:END ************************************************/
363
364
    Wrapper *f = NewWrapper();
364
 
    Wrapper_add_local(f, "SWIG_arg", "int SWIG_arg = -1");
 
365
    Wrapper_add_local(f, "SWIG_arg", "int SWIG_arg = 0");
365
366
 
366
367
 
367
368
    String *wname = Swig_name_wrapper(iname);
382
383
       it will print
383
384
         int arg1;
384
385
         int arg2;
385
 
         int result;
386
386
    NEW LANGUAGE NOTE:END ************************************************/
387
387
    /* Write code to extract function parameters. */
388
 
    emit_args(d, l, f);
 
388
    emit_parameter_variables(l, f);
389
389
 
390
390
    /* Attach the standard typemaps */
391
391
    emit_attach_parmmaps(l, f);
490
490
        Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
491
491
        break;
492
492
      }
493
 
 
494
 
      p = nextSibling(p);
495
493
    }
496
494
 
497
495
    // add all argcheck code
553
551
    Setattr(n, "wrap:name", wname);
554
552
 
555
553
    /* Emit the function call */
556
 
    emit_action(n, f);
 
554
    String *actioncode = emit_action(n);
557
555
 
558
556
    /* NEW LANGUAGE NOTE:***********************************************
559
557
    FIXME:
560
558
    returns 1 if there is a void return type
561
559
    this is because there is a typemap for void
562
560
    NEW LANGUAGE NOTE:END ************************************************/
563
 
    Printv(f->code, "SWIG_arg=0;\n", NIL);
564
561
    // Return value if necessary
565
 
    if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) {
 
562
    if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) {
566
563
      // managing the number of returning variables
567
564
      //      if (numoutputs=Getattr(tm,"numoutputs")){
568
565
      //              int i=GetInt(tm,"numoutputs");
581
578
    } else {
582
579
      Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name);
583
580
    }
 
581
    emit_return_variable(n, d, f);
584
582
 
585
583
    /* Output argument output code */
586
584
    Printv(f->code, outarg, NIL);
590
588
 
591
589
    /* Look to see if there is any newfree cleanup code */
592
590
    if (GetFlag(n, "feature:new")) {
593
 
      if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) {
 
591
      if ((tm = Swig_typemap_lookup("newfree", n, "result", 0))) {
594
592
        Replaceall(tm, "$source", "result");
595
593
        Printf(f->code, "%s\n", tm);
596
594
      }
597
595
    }
598
596
 
599
597
    /* See if there is any return cleanup code */
600
 
    if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) {
 
598
    if ((tm = Swig_typemap_lookup("ret", n, "result", 0))) {
601
599
      Replaceall(tm, "$source", "result");
602
600
      Printf(f->code, "%s\n", tm);
603
601
    }
620
618
    Replaceall(f->code, "$result", "result");
621
619
 
622
620
    /* Dump the function out */
623
 
    Wrapper_print(f, f_wrappers);
624
 
 
 
621
    /* in Lua we will not emit the destructor as a wrappered function,
 
622
    Lua will automatically call the destructor when the object is free'd
 
623
    However: you cannot just skip this function as it will not emit
 
624
    any custom destructor (using %extend), as you need to call emit_action()
 
625
    Therefore we go though the whole function, 
 
626
    but do not write the code into the wrapper
 
627
    */
 
628
    if(current!=DESTRUCTOR) {
 
629
       Wrapper_print(f, f_wrappers);
 
630
    }
 
631
    
625
632
    /* NEW LANGUAGE NOTE:***********************************************
626
633
    register the function in SWIG
627
634
    different language mappings seem to use different ideas
689
696
 
690
697
    Replaceall(dispatch, "$args", "self,args");
691
698
    Printv(f->code, dispatch, "\n", NIL);
692
 
    Printf(f->code, "lua_pushstring(L,\"No matching function for overloaded '%s'\");\n", symname);
 
699
    
 
700
    Node *sibl = n;
 
701
    while (Getattr(sibl, "sym:previousSibling"))
 
702
      sibl = Getattr(sibl, "sym:previousSibling");      // go all the way up
 
703
    String *protoTypes = NewString("");
 
704
    do {
 
705
      Printf(protoTypes, "\n\"    %s(%s)\\n\"", SwigType_str(Getattr(sibl, "name"), 0), ParmList_protostr(Getattr(sibl, "wrap:parms")));
 
706
    } while ((sibl = Getattr(sibl, "sym:nextSibling")));
 
707
    Printf(f->code, "lua_pushstring(L,\"Wrong arguments for overloaded function '%s'\\n\"\n"
 
708
        "\"  Possible C/C++ prototypes are:\\n\"%s);\n",symname,protoTypes);
 
709
    Delete(protoTypes);
 
710
 
693
711
    Printf(f->code, "lua_error(L);return 0;\n");
694
712
    Printv(f->code, "}\n", NIL);
695
713
    Wrapper_print(f, f_wrappers);
730
748
    // I refered to the Language::variableWrapper() to find this out
731
749
    bool assignable=is_assignable(n) ? true : false;
732
750
    SwigType *type = Getattr(n, "type");
733
 
    String *tm = Swig_typemap_lookup_new("globalin", n, iname, 0);
 
751
    String *tm = Swig_typemap_lookup("globalin", n, iname, 0);
734
752
    if (!tm && SwigType_isarray(type))
735
753
      assignable=false;
736
754
    Delete(tm);
774
792
      value = Char(wname);
775
793
    }
776
794
 
777
 
    if ((tm = Swig_typemap_lookup_new("consttab", n, name, 0))) {
 
795
    if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
778
796
      Replaceall(tm, "$source", value);
779
797
      Replaceall(tm, "$target", name);
780
798
      Replaceall(tm, "$value", value);
781
799
      Replaceall(tm, "$nsname", nsname);
782
800
      Printf(s_const_tab, "%s,\n", tm);
783
 
    } else if ((tm = Swig_typemap_lookup_new("constcode", n, name, 0))) {
 
801
    } else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
784
802
      Replaceall(tm, "$source", value);
785
803
      Replaceall(tm, "$target", name);
786
804
      Replaceall(tm, "$value", value);
840
858
   * ------------------------------------------------------------ */
841
859
 
842
860
  virtual int classHandler(Node *n) {
843
 
    REPORT("classHandler", n);
 
861
    //REPORT("classHandler", n);
844
862
 
845
863
    String *mangled_classname = 0;
846
864
    String *real_classname = 0;
892
910
 
893
911
    // Register the class structure with the type checker
894
912
    //    Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_classname);
 
913
 
 
914
    // emit a function to be called to delete the object 
895
915
    if (have_destructor) {
896
916
      Printv(f_wrappers, "static void swig_delete_", class_name, "(void *obj) {\n", NIL);
897
917
      if (destructor_action) {
898
918
        Printv(f_wrappers, SwigType_str(rt, "arg1"), " = (", SwigType_str(rt, 0), ") obj;\n", NIL);
899
 
        Printv(f_wrappers, destructor_action, NIL);
 
919
        Printv(f_wrappers, destructor_action, "\n", NIL);
900
920
      } else {
901
921
        if (CPlusPlus) {
902
922
          Printv(f_wrappers, "    delete (", SwigType_str(rt, 0), ") obj;\n", NIL);
1061
1081
   * ------------------------------------------------------------ */
1062
1082
 
1063
1083
  virtual int destructorHandler(Node *n) {
1064
 
    //REPORT("destructorHandler", n);
 
1084
    REPORT("destructorHandler", n);
1065
1085
    current = DESTRUCTOR;
1066
1086
    Language::destructorHandler(n);
1067
1087
    current = NO_CPP;
1079
1099
  virtual int staticmemberfunctionHandler(Node *n) {
1080
1100
    current = STATIC_FUNC;
1081
1101
    return Language::staticmemberfunctionHandler(n);
1082
 
    current = NO_CPP;
1083
1102
  }
1084
1103
 
1085
1104
  /* ------------------------------------------------------------
1101
1120
    //    REPORT("staticmembervariableHandler",n);
1102
1121
    current = STATIC_VAR;
1103
1122
    return Language::staticmembervariableHandler(n);
1104
 
    current = NO_CPP;
1105
1123
  }
1106
1124
 
1107
1125
  /* ---------------------------------------------------------------------