Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8072 in orxonox.OLD for branches


Ignore:
Timestamp:
Jun 1, 2006, 3:26:41 PM (19 years ago)
Author:
snellen
Message:

multiple return values from lua functions are now supported

Location:
branches/script_engine/src/lib/script_engine
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/lib/script_engine/Script.cc

    r8066 r8072  
    175175       returnValue = (int)lua_tonumber(luaState, -1);
    176176       returnCount--;
     177       lua_pop(luaState,1);
    177178     }
    178179   }
     
    190191       returnValue = (bool)lua_toboolean(luaState, -1);
    191192       returnCount--;
     193       lua_pop(luaState,1);
    192194     }
    193195   }
     
    195197 }
    196198
     199float Script::getReturnedFloat()
     200 {
     201   float returnValue;
     202   if(returnCount > 0)
     203   {
     204     if(lua_isnumber(luaState, -1))
     205     {
     206       returnValue = (float)lua_tonumber(luaState, -1);
     207       returnCount--;
     208       lua_pop(luaState,1);
     209     }
     210   }
     211   return returnValue;
     212 }
    197213
    198214 int Script::reportError(int error)
  • branches/script_engine/src/lib/script_engine/Script.h

    r8066 r8072  
    2323    bool executeFunction();
    2424    // push parameters for luafunction
    25     bool pushParam(int param, std::string& toFunction);//overload this function to add different types
    26     bool pushParam(float param, std::string& toFunction);
    27     bool pushParam(double param, std::string& toFunction);
    28     // get returned values
    29     int  getReturnedInt();//overload this function to get different types
    30     bool getReturnedBool();
     25    bool  pushParam(int param, std::string& toFunction);//overload this function to add different types
     26    bool  pushParam(float param, std::string& toFunction);
     27    bool  pushParam(double param, std::string& toFunction);
     28    // get returned values the last return value in lua is the first in c.
     29    int   getReturnedInt();//overload this function to get different types
     30    bool  getReturnedBool();
     31    float getReturnedFloat();
    3132
    3233
  • branches/script_engine/src/lib/script_engine/account.cc

    r8061 r8072  
    8989
    9090      std::string main("main");
    91       if( script.selectFunction(main,1))
     91      if( script.selectFunction(main,3))
    9292       printf("function %s selected\n",main.c_str());
    9393
     
    9595      script.executeFunction();
    9696
     97      float retf = script.getReturnedFloat();
     98      printf("main returned %f\n",retf);
     99     
     100
     101      if(script.getReturnedBool())
     102       printf("main returned true\n");
     103      else
     104       printf("main returned false\n");
     105
    97106      int ret = script.getReturnedInt();
    98107      printf("main returned %i\n",ret);
    99 
     108     
    100109      //if(argc>1) lua_dofile(script.getLuaState(), argv[1]);
    101110
  • branches/script_engine/src/lib/script_engine/lunartest2.lua

    r8061 r8072  
    2828  Obj:printName()
    2929
    30   return 2
     30  return 2,false,2.72
    3131  --debug.debug()
    3232end
Note: See TracChangeset for help on using the changeset viewer.