Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8085 in orxonox.OLD


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

started implementing script_manager

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

Legend:

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

    r8080 r8085  
    9191    {
    9292      Script script;
     93      printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
    9394
    9495      // Register classes with the script
     
    104105      Lunar<Account>::insertObject(&script,&a,"a",false);
    105106      Lunar<Account>::insertObject(&script,b,"b",true);
    106 
    107 
     107       printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
     108      //Load a file
    108109      std::string file(argv[1]);
    109110
    110111      if(script.loadFile(file))
    111112        printf("File %s succefully loaded\n", file.c_str());
    112 
    113       //script.executeFile();
    114 
     113      printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
     114      //execute a function
     115      printf("----------- main -----------\n");
    115116      std::string main("main");
    116117      if( script.selectFunction(main,3))
     
    131132      int ret = script.getReturnedInt();
    132133      printf("main returned %i\n",ret);
     134
     135      printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
     136      //execute a 2nd function
     137      printf("----------- test -----------\n");
     138      std::string test("test");
     139      if( script.selectFunction(test,0))
     140       printf("function %s selected\n",test.c_str());
     141
     142      script.executeFunction();
     143
    133144     
    134145      //if(argc>1) lua_dofile(script.getLuaState(), argv[1]);
     146      printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
    135147
    136148      return 0;
  • branches/script_engine/src/lib/script_engine/lunartest2.lua

    r8080 r8085  
    1414
    1515getmetatable(Account).__index = parent
     16
     17
     18function test()
     19io.write("Hi i'm test\n")
     20end
     21
    1622
    1723function main(arg)
  • branches/script_engine/src/lib/script_engine/script.cc

    r8075 r8085  
    2929
    3030   if(currentFile.length() != 0)
     31   {
    3132     printf("Could not load %s because an other file is already loaded: %s\n",filename.c_str(), currentFile.c_str());
     33     return false;
     34    }
    3235
    3336   int error = luaL_loadfile (luaState, filename.c_str());
     
    7477 bool Script::selectFunction(std::string& functionName, int retCount)
    7578 {
    76    if(returnCount == 0) //no return values left on the stack
     79   if(returnCount == 0 && currentFunction.length() == 0) //no return values left on the stack and no other function selected
    7780   {
    7881   lua_pushlstring(luaState, functionName.c_str(), functionName.size() );
     
    9093   }
    9194   else
    92      printf("there are unremoved return values on the stack. Please remove them first.\n");
     95     printf("There is an other function active ( %s ) or there are unremoved return values on the stack. Please remove them first.\n",currentFunction.c_str());
     96   return false;
    9397 }
    9498
     
    214218 int Script::reportError(int error)
    215219 {
    216  const char *msg = lua_tostring(luaState, -1);
    217  if (msg == NULL) msg = "(error with no message)";
    218  fprintf(stderr, "ERROR: %s\n", msg);
    219  lua_pop(luaState, 1);
    220  return error;
    221  }
    222 
     220 if(error != 0)
     221 {
     222  const char *msg = lua_tostring(luaState, -1);
     223  if (msg == NULL) msg = "(error with no message)";
     224  fprintf(stderr, "ERROR: %s\n", msg);
     225  lua_pop(luaState, 1);
     226  return error;
     227 }
     228 }
     229
  • branches/script_engine/src/lib/script_engine/script_manager.cc

    r8072 r8085  
     1
     2#include "script.h"
     3#include "script_manager.h"
  • branches/script_engine/src/lib/script_engine/script_manager.h

    r8072 r8085  
     1#ifndef _SCRIPT_MANAGER_H
     2#define _SCRIPT_MNAGER_H
     3
     4
     5#include <string>
     6#include "base_object.h"
     7
     8#include "luaincl.h"
     9
     10
     11
     12class ScriptManager
     13{
     14 public:
     15
     16
     17
     18
     19
     20 private:
     21
     22
     23
     24};
     25#endif
Note: See TracChangeset for help on using the changeset viewer.