- Timestamp:
- Jun 1, 2006, 7:24:22 PM (19 years ago)
- Location:
- branches/script_engine/src/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/script_engine/Makefile.am
r8100 r8101 1 1 MAINSRCDIR=../.. 2 2 include $(MAINSRCDIR)/defs/include_paths.am 3 4 5 LIB_PREFIX=$(MAINSRCDIR)/lib 6 include $(MAINSRCDIR)/lib/BuildLibs.am 7 8 3 9 4 10 INCLUDES= -I../../../extern_libs … … 13 19 14 20 bin_PROGRAMS = example 15 example_SOURCES = \16 example.cc \17 \18 ../util/executor/executor_lua.cc19 21 20 22 21 22 23 example_LDADD = libORXscript.a -L../../../extern_libs @LUA_LIBS@24 25 #main_LDFLAGS =26 23 27 24 … … 31 28 script.h\ 32 29 script_manager.h 30 31 32 33 example_DEPENDENCIES = \ 34 $(MAINSRCDIR)/world_entities/libORXwe.a \ 35 $(libORXlibs_a_LIBRARIES_) \ 36 $(MAINSRCDIR)/util/libORXutils.a 37 38 example_LDADD = \ 39 $(MAINSRCDIR)/util/libORXutils.a \ 40 $(libORXlibs_a_LIBRARIES_) \ 41 libORXscript.a -L../../../extern_libs @LUA_LIBS@ \ 42 $(MAINSRCDIR)/world_entities/libORXwe.a \ 43 $(libORXlibs_a_LIBRARIES_) \ 44 $(MAINSRCDIR)/util/libORXutils.a 45 46 example_SOURCES= \ 47 example.cc \ 48 \ 49 ../util/executor/executor_lua.cc -
branches/script_engine/src/lib/script_engine/example.cc
r8093 r8101 6 6 #include "script.h" 7 7 8 class Account { 8 9 class Account : public BaseObject { 9 10 lua_Number m_balance; 10 11 public: … … 14 15 Account(lua_State *L) { m_balance = luaL_checknumber(L, 1); } 15 16 Account(double balance=0) : m_balance(balance) { } 17 18 void deposit (float value) { m_balance += value; }; 19 void withdraw(float value) { m_balance -= value; }; 20 float balance() { return m_balance; };;;;;;;;;;;;;; 21 16 22 int deposit (lua_State *L) { m_balance += luaL_checknumber(L, 1); return 0; } 17 23 int withdraw(lua_State *L) { m_balance -= luaL_checknumber(L, 1); return 0; } … … 26 32 27 33 Lunar<Account>::RegType Account::methods[] = { 28 method(Account, deposit),29 method(Account, withdraw),30 method(Account, balance),31 {0, 0}34 {"deposit", new ExecutorLua1<Account, float>(&Account::deposit)}, 35 {"withdraw", new ExecutorLua1<Account, float>(&Account::withdraw)}, 36 {"balance", new ExecutorLua0ret<Account, float>(&Account::balance)}, 37 {0,NULL} 32 38 }; 33 39 34 40 35 class Object {41 class Object : public BaseObject { 36 42 public: 37 43 static const char className[]; … … 47 53 { 48 54 int calls = getCallCount(); 49 lua_pushnumber(L,(lua_Number)calls); 55 lua_pushnumber(L,(lua_Number)calls); 50 56 return 1; // return number of values that the function wants to return to lua 51 57 } … … 53 59 //function that takes an argument from lua 54 60 int takeParam(lua_State* L) 55 { 61 { 56 62 int param = (int)lua_tonumber(L,-1); 57 63 takeParam(param); 58 return 0; 64 return 0; 59 65 } 60 66 … … 67 73 int printName(lua_State* L) 68 74 { 69 callCount ++; 70 printf("Hi i'm object %p ! This is the %i. call.\n",this,callCount); 75 this->printName(); 71 76 return 0; 72 77 } 73 78 74 int getCallCount(){return callCount;} 79 void printName() 80 { 81 callCount ++; 82 printf("Hi i'm object %p ! This is the %i. call.\n",this,callCount); 83 } 84 85 int getCallCount(){ return callCount; } 75 86 76 87 private: … … 82 93 83 94 Lunar<Object>::RegType Object::methods[] = { 84 method(Object, printName),85 method(Object, getCallCount),86 method(Object, takeParam),95 {"printName", new ExecutorLua0<Object>(&Object::printName)}, 96 {"getCallCount", new ExecutorLua0ret<Object, int>(&Object::getCallCount)}, 97 {"takeParam", new ExecutorLua1<Object, int>(&Object::takeParam)}, 87 98 {0,0} 88 99 }; … … 123 134 float retf = script.getReturnedFloat(); 124 135 printf("main returned %f\n",retf); 125 136 126 137 127 138 if(script.getReturnedBool()) … … 142 153 script.executeFunction(); 143 154 144 155 145 156 //if(argc>1) lua_dofile(script.getLuaState(), argv[1]); 146 157 printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState())); -
branches/script_engine/src/lib/script_engine/lunar.h
r8092 r8101 13 13 typedef struct { T *pT; } userdataType; 14 14 public: 15 typedef int (T::*mfp)(lua_State *L);15 typedef Executor* mfp; 16 16 typedef struct { const char *name; mfp mfunc; } RegType; 17 17 … … 164 164 // get member function from upvalue 165 165 RegType *l = static_cast<RegType*>(lua_touserdata(L, lua_upvalueindex(1))); 166 return (obj->*(l->mfunc))(L); // call member function 166 int value; 167 (*l->mfunc)(obj, value, L); // call member function 168 return value; 167 169 } 168 170 -
branches/script_engine/src/lib/util/executor/executor_lua.h
r8098 r8101 75 75 return new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer)); 76 76 } 77 private: 78 void (T::*functionPointer)(); 77 79 }; 78 80 … … 122 124 return new ExecutorLua1<T, type0>((this->functionPointer)); 123 125 } 126 private: 127 void (T::*functionPointer)(type0); 124 128 }; 125 129 … … 171 175 return new ExecutorLua2<T, type0, type1>(this->functionPointer); 172 176 } 177 private: 178 void (T::*functionPointer)(type0, type1); 173 179 }; 174 180 … … 227 233 return new ExecutorLua0ret<T, ret>(this->functionPointer); 228 234 } 235 private: 236 ret (T::*functionPointer)(); 229 237 }; 230 238 … … 275 283 return new ExecutorLua1ret<T, ret, type0>(this->functionPointer); 276 284 } 285 private: 286 ret (T::*functionPointer)(type0); 277 287 }; 278 288 … … 322 332 return new ExecutorLua2ret<T, ret, type0, type1>(this->functionPointer); 323 333 } 334 private: 335 ret (T::*functionPointer)(type0, type1); 324 336 }; 325 337
Note: See TracChangeset
for help on using the changeset viewer.