Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8066 in orxonox.OLD for branches/script_engine/src/lib


Ignore:
Timestamp:
Jun 1, 2006, 2:06:34 PM (18 years ago)
Author:
snellen
Message:

return values form a lua works now

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

Legend:

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

    r8061 r8066  
    7474 bool Script::selectFunction(std::string& functionName, int retCount)
    7575 {
     76   if(returnCount == 0) //no return values left on the stack
     77   {
    7678   lua_pushlstring(luaState, functionName.c_str(), functionName.size() );
    7779   lua_gettable(luaState, LUA_GLOBALSINDEX);
     
    8688   else
    8789    return false;
    88 
     90   }
     91   else
     92     printf("there are unremoved return values on the stack. Please remove them first.\n");
    8993 }
    9094
     
    103107    {
    104108      currentFunction.assign("");//a function gets unusable after beeing called for the first time
    105       returnCount = argumentCount = 0;
     109      argumentCount = 0;
    106110      return true;
    107111    }
     
    164168 int Script::getReturnedInt()
    165169 {
     170   int returnValue;
    166171   if(returnCount > 0)
    167172   {
    168      printf("int found");
    169      if(lua_isnumber(luaState, 1))
    170      {
    171        printf("int found");
    172        int returnValue = (int)lua_tonumber(luaState, 1);
     173     if(lua_isnumber(luaState, -1))
     174     {
     175       returnValue = (int)lua_tonumber(luaState, -1);
    173176       returnCount--;
    174177     }
    175178   }
     179   return returnValue;
     180 }
     181
     182
     183 bool Script::getReturnedBool()
     184 {
     185   bool returnValue;
     186   if(returnCount > 0)
     187   {
     188     if(lua_isboolean(luaState, -1))
     189     {
     190       returnValue = (bool)lua_toboolean(luaState, -1);
     191       returnCount--;
     192     }
     193   }
     194   return returnValue;
    176195 }
    177196
  • branches/script_engine/src/lib/script_engine/Script.h

    r8061 r8066  
    2222    bool selectFunction(std::string& functionName, int retCount);
    2323    bool executeFunction();
     24    // push parameters for luafunction
    2425    bool pushParam(int param, std::string& toFunction);//overload this function to add different types
    2526    bool pushParam(float param, std::string& toFunction);
    2627    bool pushParam(double param, std::string& toFunction);
    27     int  getReturnedInt();
    28 
     28    // get returned values
     29    int  getReturnedInt();//overload this function to get different types
     30    bool getReturnedBool();
    2931
    3032
Note: See TracChangeset for help on using the changeset viewer.