Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1102


Ignore:
Timestamp:
Apr 17, 2008, 3:40:12 PM (16 years ago)
Author:
bknecht
Message:

lua50 compatiple level code and loading, should work on tardis as well now

Location:
code/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/bin/levels/sample.oxw

    r1089 r1102  
    3838
    3939
    40 <!--?lua
     40<?lua
    4141for i = 1, 226, 1
    4242do ?>
    43   <Model position="<?lua print(math.random(-19597, 18732))?>, <?lua print(math.random(-19597, 18732)) ?>, <?lua print(math.random(-19597, 18732)) ?>" scale="<?lua print(math.random( 20, 119)) ?>" mesh="ast<?lua print(i%6 + 1) ?>.mesh" rotationAxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationRate="<?lua print(math.random(16, 44)) ?>" />
     43  <Model position="<?lua print(math.random(-19597, 18732))?>, <?lua print(math.random(-19597, 18732)) ?>, <?lua print(math.random(-19597, 18732)) ?>" scale="<?lua print(math.random( 20, 119)) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" rotationAxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationRate="<?lua print(math.random(16, 44)) ?>" />
    4444<?lua
    4545end
    46 ?-->
     46?>
  • code/trunk/src/core/Loader.cc

    r1085 r1102  
    115115        Script::init(Script::getLuaState());
    116116        Script::run();*/
    117         //Script* lua = Script::getInstance();
    118         //lua->loadFile(level->getFile(), true);
    119         //lua->run();
     117        Script* lua = Script::getInstance();
     118        lua->loadFile(level->getFile(), true);
     119        lua->run();
    120120
    121121        try
     
    124124            COUT(3) << "Mask: " << Loader::currentMask_s << std::endl;
    125125
    126             ticpp::Document xmlfile(level->getFile());
    127             xmlfile.LoadFile();
     126            //ticpp::Document xmlfile(level->getFile());
     127            //xmlfile.LoadFile();
    128128            //ticpp::Element myelement(*Script::getFileString());
    129             //ticpp::Document xmlfile;
    130             xmlfile.ToDocument();
    131             //xmlfile.Parse(lua->getLuaOutput(), true);
     129            ticpp::Document xmlfile;
     130            //xmlfile.ToDocument();
     131            xmlfile.Parse(lua->getLuaOutput(), true);
    132132
    133133            ticpp::Element rootElement;
  • code/trunk/src/core/Script.cc

    r1076 r1102  
    102102  }
    103103
     104#if LUA_VERSION_NUM != 501
     105  const char * Script::lua_Chunkreader(lua_State *L, void *data, size_t *size)
     106  {
     107    LoadS* ls = ((LoadS*)data);
     108    if (ls->size == 0) return NULL;
     109    *size = ls->size;
     110    ls->size = 0;
     111    return ls->s;
     112  }
     113#endif
    104114  void Script::run()
    105115  {
     
    110120    error = luaL_loadstring(luaState_, init.c_str());
    111121#else
    112     error = lua_load(luaState_, &orxonox::Script::lua_Chunkreader, (void*)init.c_str(), "init");
     122    LoadS ls;
     123    ls.s = init.c_str();
     124    ls.size = init.size();
     125    error = lua_load(luaState_, &orxonox::Script::lua_Chunkreader, &ls, init.c_str());
    113126#endif
    114127    if (error == 0)
  • code/trunk/src/core/Script.h

    r1056 r1102  
    5050  class _CoreExport Script // tolua_export
    5151  { // tolua_export
     52    struct LoadS {
     53      const char *s;
     54      size_t size;
     55    };
     56
    5257    public:
    5358      inline static Script* getInstance() { if (!Script::singletonRef) Script::singletonRef = new Script(); return Script::singletonRef; } // tolua_export
     
    6166
    6267#if LUA_VERSION_NUM != 501
    63     inline static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size) { return NULL;};
     68    static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
    6469#endif
    6570
Note: See TracChangeset for help on using the changeset viewer.