Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pch/src/tolua/changes_orxonox.diff @ 3127

Last change on this file since 3127 was 3127, checked in by rgrieder, 15 years ago

Update to tolua 1.0.93

  • Property svn:eol-style set to native
File size: 4.5 KB
  • tolua++.h

     
    1616#ifndef TOLUA_H
    1717#define TOLUA_H
    1818
     19/* original code */
     20/*
    1921#ifndef TOLUA_API
    2022#define TOLUA_API extern
    2123#endif
     24*/
     25
     26/********************************
     27******* ORXONOX CHANGES *********
     28********************************/
     29
     30#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined( TOLUA_STATIC_BUILD )
     31#  ifdef TOLUA_SHARED_BUILD
     32#    define TOLUA_API __declspec(dllexport)
     33#  else
     34#    if defined( __MINGW32__ )
     35#      define TOLUA_API
     36#    else
     37#      define TOLUA_API __declspec(dllimport)
     38#    endif
     39#  endif
     40#else
     41#  define TOLUA_API extern
     42#endif
     43
     44/********************************
     45****** END ORXONOX CHANGES ******
     46********************************/
    2247
    2348#define TOLUA_VERSION "tolua++-1.0.92"
    2449
  • tolua.c

     
    44** TeCGraf/PUC-Rio
    55** Aug 2003
    66** $Id:$
     7** Extension by Orxonox (Reto Grieder) to support working directory
     8** and direct usage of lua files. (2008)
    79*/
    810
    911/* This code is free software; you can redistribute it and/or modify it.
     
    3335         "  -o  file : set output file; default is stdout.\n"
    3436         "  -H  file : create include file.\n"
    3537         "  -n  name : set package name; default is input file root name.\n"
     38         "  -w  directory : set working directory; default is location of package file.\n"
     39         "  -s  file : specify source lua code for the parser; all.lua is default.\n"
    3640         "  -p       : parse only.\n"
    3741         "  -P       : parse and print structure information (for debug).\n"
    3842         "  -S       : disable support for c++ strings.\n"
     
    6569}
    6670
    6771static void add_extra (lua_State* L, char* value) {
    68         int len;
    69         lua_getglobal(L, "_extra_parameters");
    70         len = luaL_getn(L, -1);
    71         lua_pushstring(L, value);
    72         lua_rawseti(L, -2, len+1);
    73         lua_pop(L, 1);
     72 int len;
     73 lua_getglobal(L, "_extra_parameters");
     74 len = luaL_getn(L, -1);
     75 lua_pushstring(L, value);
     76 lua_rawseti(L, -2, len+1);
     77 lua_pop(L, 1);
    7478};
    7579
    7680static void error (char* o)
     
    8286
    8387int main (int argc, char* argv[])
    8488{
     89 char* working_directory = "";
     90 char* lua_source = "";
     91
    8592 #ifdef LUA_VERSION_NUM /* lua 5.1 */
    8693 lua_State* L = luaL_newstate();
    8794 luaL_openlibs(L);
     
    98105 lua_pushstring(L,TOLUA_VERSION); lua_setglobal(L,"TOLUA_VERSION");
    99106 lua_pushstring(L,LUA_VERSION); lua_setglobal(L,"TOLUA_LUA_VERSION");
    100107
     108
    101109 if (argc==1)
    102110 {
    103111  help();
     
    125133     case 'o': setfield(L,t,"o",argv[++i]); break;
    126134     case 'n': setfield(L,t,"n",argv[++i]); break;
    127135     case 'H': setfield(L,t,"H",argv[++i]); break;
     136     case 'w':
     137      working_directory = argv[++i];
     138      setfield(L,t,"w",argv[i]);
     139      break;
     140     case 's':
     141      lua_source = argv[++i];
     142      setfield(L,t,"s",argv[i]);
     143      break;
    128144     case 'S': setfield(L,t,"S",""); break;
    129145     case '1': setfield(L,t,"1",""); break;
    130146     case 'L': setfield(L,t,"L",argv[++i]); break;
     
    145161  }
    146162  lua_pop(L,1);
    147163 }
    148 /* #define TOLUA_SCRIPT_RUN */
    149 #ifndef TOLUA_SCRIPT_RUN
     164
    150165 {
    151   int tolua_tolua_open (lua_State* L);
    152   tolua_tolua_open(L);
    153  }
     166  char path[BUFSIZ];
     167  char file[BUFSIZ];
     168  path[0] = '\0';
     169  file[0] = '\0';
     170
     171  if (strlen(lua_source) > 0 &&
     172      lua_source[0] != '/' &&
     173      lua_source[0] != '\\' &&
     174      strlen(lua_source) > 1 &&
     175      lua_source[1] != ':')
     176  {
     177   /* Relative path, prefix working directory */
     178   strcpy(path, working_directory);
     179   /* Make sure there is '\\' or '/' at the end of the path */
     180   if (strlen(path) > 0)
     181   {
     182    char last = path[strlen(path) - 1];
     183    if (last != '\\' && last != '/')
     184     strcat(path, "/");
     185   }
     186  }
     187
     188  strcat(path, lua_source);
     189
     190  /* Extract the full path */
     191  {
     192   char* p;
     193   p = strrchr(path, '/');
     194   if (p == NULL)
     195    p = strrchr(path, '\\');
     196   p = (p == NULL) ? path : p + 1;
     197   strcpy(file, p);
     198   *p = '\0';
     199  }
     200  if (strlen(file) == 0)
     201   strcpy(file, "all.lua");
     202
     203  lua_pushstring(L, path);
     204  lua_setglobal(L, "path");
     205  strcat(path, file);
     206#ifdef LUA_VERSION_NUM /* lua 5.1 */
     207  luaL_dofile(L, path);
    154208#else
    155  {
    156   char* p;
    157   char  path[BUFSIZ];
    158   strcpy(path,argv[0]);
    159   p = strrchr(path,'/');
    160   if (p==NULL) p = strrchr(path,'\\');
    161   p = (p==NULL) ? path : p+1;
    162   sprintf(p,"%s","../src/bin/lua/");
    163   lua_pushstring(L,path); lua_setglobal(L,"path");
    164                 strcat(path,"all.lua");
    165   lua_dofile(L,path);
    166  }
     209  lua_dofile(L, path);
    167210#endif
     211 }
    168212 return 0;
    169213}
Note: See TracBrowser for help on using the repository browser.