Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8080 in orxonox.OLD


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

added example how to return values to lua

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

Legend:

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

    r8078 r8080  
    4343
    4444        //lua Interface
    45         int getCallCount(lua_State* L){int calls = getCallCount(); lua_pushnumber(L,(lua_Number)calls);return 1;}
     45        //function that returns a value to lua
     46        int getCallCount(lua_State* L)
     47        {
     48         int calls = getCallCount();
     49         lua_pushnumber(L,(lua_Number)calls);
     50         return 1; // return number of values that the function wants to return to lua
     51        }
    4652
     53         //function that takes an argument from lua
     54         int takeParam(lua_State* L)
     55         {
     56          int param = (int)lua_tonumber(L,-1);
     57          takeParam(param);
     58          return 0;
     59         }
     60
     61        //meber functions
     62        void takeParam(int i)
     63        {
     64         printf("Lua passed %i to c++\n",i);
     65        }
    4766
    4867        int printName(lua_State* L)
     
    6584      method(Object, printName),
    6685      method(Object, getCallCount),
     86      method(Object, takeParam),
    6787      {0,0}
    6888    };
  • branches/script_engine/src/lib/script_engine/lunartest2.lua

    r8078 r8080  
    1818  io.write("main received ", arg)
    1919  io.write(" as parameter\n")
     20  --call member
    2021  Obj:printName()
     22
     23  --create object
     24
     25  o = Object()
     26  o:printName()
     27
     28  --take returnvalue from c
    2129  callCount = Obj:getCallCount()
    2230  io.write("callCount is now ",callCount)
    2331  io.write("\n")
     32 
     33  --pass parameters to a c++ method
     34  Obj:takeParam(3)
    2435
     36  --print object information
    2537  print('a =', a)
    2638  print('b =', b)
Note: See TracChangeset for help on using the changeset viewer.