Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

added function to get a int as a return value from a lua function

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

Legend:

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

    r8045 r8058  
    7474 bool Script::selectFunction(std::string& functionName, int retCount)
    7575 {
    76 
    77    returnCount = retCount;
    78    argumentCount = 0;
    79    currentFunction = functionName;
    80    lua_pushlstring(luaState, currentFunction.c_str(), currentFunction.size() );
     76   lua_pushlstring(luaState, functionName.c_str(), functionName.size() );
    8177   lua_gettable(luaState, LUA_GLOBALSINDEX);
    8278
    83   /* if(lua_isfunction( luaState , -1))
     79  if(lua_isfunction( luaState , -1))
    8480   {
     81     returnCount = retCount;
     82     argumentCount = 0;
     83     currentFunction = functionName;
    8584     return true;
    8685   }
    8786   else
    88    return false;*/
    89    return true;
     87    return false;
     88
    9089 }
    9190
     
    163162 }
    164163
     164 int Script::getReturnedInt()
     165 {
     166   if(returnCount > 0)
     167   {
     168     if(lua_isnumber(luaState, 1))
     169     {
     170       printf("int found");
     171       int returnValue = (int)lua_tonumber(luaState, 1);
     172       returnCount--;
     173     }
     174   }
     175 }
     176
     177
    165178 int Script::reportError(int error)
    166179 {
  • branches/script_engine/src/lib/script_engine/Script.h

    r8045 r8058  
    2525    bool pushParam(float param, std::string& toFunction);
    2626    bool pushParam(double param, std::string& toFunction);
    27 
     27    int  getReturnedInt();
    2828
    2929
  • branches/script_engine/src/lib/script_engine/account.cc

    r8045 r8058  
    8989
    9090      std::string main("main");
    91       script.selectFunction(main,0);
     91      if( script.selectFunction(main,0))
     92       printf("function %s selected\n",main.c_str());
     93
    9294      script.pushParam(3.14159,main);
    9395      script.executeFunction();
     96
     97      int ret = script.getReturnedInt();
     98      printf("main returned %i\n",ret);
    9499
    95100      //if(argc>1) lua_dofile(script.getLuaState(), argv[1]);
  • branches/script_engine/src/lib/script_engine/lunartest2.lua

    r8046 r8058  
    2727  a:show() a:deposit(50.30) a:show() a:withdraw(25.10) a:show()
    2828  Obj:printName()
     29
     30  return 2
    2931  --debug.debug()
    3032end
Note: See TracChangeset for help on using the changeset viewer.