Changeset 8231 in orxonox.OLD for branches/script_engine/src/lib
- Timestamp:
- Jun 8, 2006, 12:21:21 PM (18 years ago)
- Location:
- branches/script_engine/src/lib/script_engine
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/script_engine/example.cc
r8128 r8231 6 6 #include "script.h" 7 7 8 // create classdummys for the scripts 9 CREATE_SCRIPTABLE_CLASS(Account, CL_ACCOUNT) 10 CREATE_SCRIPTABLE_CLASS(Object, CL_TEST_OBJECT) 8 11 9 12 class Account : public BaseObject { … … 81 84 int main(int argc, char *argv[]) 82 85 { 83 Script script; 84 printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState())); 86 std::string file("lunartest2.lua"); 87 // Script script; 88 Script* script = ScriptManager::getInstance()->getScriptByFile(file); 89 printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState())); 85 90 86 91 // Register classes with the script 87 Lunar<Account>::Register(&script);88 Lunar<Object>::Register(&script);92 // Lunar<Account>::Register(&script); 93 //Lunar<Object>::Register(&script); 89 94 90 Object* obj= new Object();91 Account a;92 Account *b = new Account(30);95 //Object* obj= new Object(); 96 //Account a; 97 //Account *b = new Account(30); 93 98 94 99 // Add instances to the script 95 Lunar<Object>::insertObject(&script,obj,"Obj",true);96 Lunar<Account>::insertObject(&script,&a,"a",false);97 Lunar<Account>::insertObject(&script,b,"b",true);98 printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));100 //Lunar<Object>::insertObject(&script,obj,"Obj",true); 101 //Lunar<Account>::insertObject(&script,&a,"a",false); 102 //Lunar<Account>::insertObject(&script,b,"b",true); 103 //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState())); 99 104 100 105 //Load a file 101 std::string file(argv[1]);106 //std::string file("lunartest2.lua"); 102 107 103 if(script.loadFile(file))104 printf("File %s succefully loaded\n", file.c_str());105 printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));108 //if(script.loadFile(file)) 109 //printf("File %s succefully loaded\n", file.c_str()); 110 //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState())); 106 111 107 112 //execute a function 108 113 printf("----------- main -----------\n"); 109 114 std::string main("main"); 110 if( script .selectFunction(main,3))115 if( script->selectFunction(main,3)) 111 116 printf("function %s selected\n",main.c_str()); 112 117 113 script .pushParam(3.14159,main);114 script .executeFunction();118 script->pushParam(3.14159,main); 119 script->executeFunction(); 115 120 116 float retf = script .getReturnedFloat();121 float retf = script->getReturnedFloat(); 117 122 printf("main returned %f\n",retf); 118 123 119 124 120 if(script .getReturnedBool())125 if(script->getReturnedBool()) 121 126 printf("main returned true\n"); 122 127 else 123 128 printf("main returned false\n"); 124 129 125 int ret = script .getReturnedInt();130 int ret = script->getReturnedInt(); 126 131 printf("main returned %i\n",ret); 127 132 128 printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));133 //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState())); 129 134 //execute a 2nd function 130 135 printf("----------- test -----------\n"); 131 136 std::string test("test"); 132 if( script .selectFunction(test,0))137 if( script->selectFunction(test,0)) 133 138 printf("function %s selected\n",test.c_str()); 134 139 135 script .executeFunction();140 script->executeFunction(); 136 141 137 142 138 143 //if(argc>1) lua_dofile(script.getLuaState(), argv[1]); 139 printf("-------------------------- top of the stack:%i\n",lua_gettop(script .getLuaState()));144 printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState())); 140 145 141 146 return 0; -
branches/script_engine/src/lib/script_engine/script.cc
r8207 r8231 12 12 { 13 13 this->setClassID(CL_SCRIPT, "Script"); 14 14 15 15 returnCount = argumentCount = 0; 16 16 … … 23 23 luaopen_math(luaState); 24 24 luaopen_debug(luaState); 25 25 26 26 if (root != NULL) 27 27 this->loadParams(root); … … 39 39 { 40 40 BaseObject::loadParams(root); 41 41 42 42 LOAD_PARAM_START_CYCLE(root, object); 43 43 { … … 89 89 } 90 90 91 91 92 92 void Script::addObject(const std::string& className, const std::string& objectName) 93 93 { … … 96 96 if (scriptClass != NULL) 97 97 { 98 tmpObj.type = className; 98 99 if( !classIsRegistered(className) ) 99 100 { 100 101 static_cast<ScriptClass*>(scriptClass)->registerClass(this); 101 tmpObj.type = className; 102 } 103 102 } 103 104 104 BaseObject* object = ClassList::getObject(objectName, className); 105 105 if (object != NULL && !objectIsAdded(objectName)) … … 112 112 } 113 113 114 115 116 114 115 116 117 117 bool Script::executeFile() 118 118 { 119 if(currentFile.length() != 0) 119 printf("WARNING: script.executeFile is not implemented yet"); 120 /*if(currentFile.length() != 0) 120 121 { 121 122 int error = lua_pcall(luaState, 0, 0, 0); … … 127 128 return false; 128 129 } 129 }130 }*/ 130 131 return false; 131 132 } … … 299 300 } 300 301 301 302 302 303 bool Script::classIsRegistered(const std::string& type) 303 304 { … … 311 312 return false; 312 313 } 313 314 315 314 315 316 316 317 bool Script::objectIsAdded(const std::string& name) 317 318 { … … 324 325 } 325 326 return false; 326 327 328 } 327 328 329 }
Note: See TracChangeset
for help on using the changeset viewer.