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
RevLine 
[3127]1--- tolua++.h   Tue Jun  9 16:27:17 2009
2+++ tolua++.h   Tue Jun  9 14:50:04 2009
[2604]3@@ -16,9 +16,34 @@
[2705]4 #ifndef TOLUA_H
5 #define TOLUA_H
6 
7+/* original code */
8+/*
9 #ifndef TOLUA_API
10 #define TOLUA_API extern
11 #endif
12+*/
13+
14+/********************************
15+******* ORXONOX CHANGES *********
16+********************************/
17+
18+#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined( TOLUA_STATIC_BUILD )
19+#  ifdef TOLUA_SHARED_BUILD
20+#    define TOLUA_API __declspec(dllexport)
21+#  else
22+#    if defined( __MINGW32__ )
23+#      define TOLUA_API
24+#    else
25+#      define TOLUA_API __declspec(dllimport)
26+#    endif
27+#  endif
28+#else
29+#  define TOLUA_API extern
30+#endif
31+
32+/********************************
33+****** END ORXONOX CHANGES ******
34+********************************/
35 
36 #define TOLUA_VERSION "tolua++-1.0.92"
37 
[3127]38--- tolua.c     Tue Jun  9 16:27:12 2009
39+++ tolua.c     Tue Jun  9 14:50:04 2009
[2604]40@@ -4,6 +4,8 @@
[2705]41 ** TeCGraf/PUC-Rio
42 ** Aug 2003
43 ** $Id:$
44+** Extension by Orxonox (Reto Grieder) to support working directory
45+** and direct usage of lua files. (2008)
46 */
47 
48 /* This code is free software; you can redistribute it and/or modify it.
[2604]49@@ -33,6 +35,8 @@
[2705]50          "  -o  file : set output file; default is stdout.\n"
51          "  -H  file : create include file.\n"
52          "  -n  name : set package name; default is input file root name.\n"
53+         "  -w  directory : set working directory; default is location of package file.\n"
54+         "  -s  file : specify source lua code for the parser; all.lua is default.\n"
55          "  -p       : parse only.\n"
56          "  -P       : parse and print structure information (for debug).\n"
57          "  -S       : disable support for c++ strings.\n"
[3127]58@@ -65,12 +69,12 @@
[2705]59 }
60 
61 static void add_extra (lua_State* L, char* value) {
62-       int len;
63-       lua_getglobal(L, "_extra_parameters");
64-       len = luaL_getn(L, -1);
65-       lua_pushstring(L, value);
66-       lua_rawseti(L, -2, len+1);
67-       lua_pop(L, 1);
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);
74 };
75 
76 static void error (char* o)
[3127]77@@ -82,6 +86,9 @@
[2705]78 
79 int main (int argc, char* argv[])
80 {
81+ char* working_directory = "";
82+ char* lua_source = "";
83+
84  #ifdef LUA_VERSION_NUM /* lua 5.1 */
85  lua_State* L = luaL_newstate();
86  luaL_openlibs(L);
[3127]87@@ -98,6 +105,7 @@
[2705]88  lua_pushstring(L,TOLUA_VERSION); lua_setglobal(L,"TOLUA_VERSION");
89  lua_pushstring(L,LUA_VERSION); lua_setglobal(L,"TOLUA_LUA_VERSION");
90 
91+
92  if (argc==1)
93  {
94   help();
[3127]95@@ -125,6 +133,14 @@
[2705]96      case 'o': setfield(L,t,"o",argv[++i]); break;
97      case 'n': setfield(L,t,"n",argv[++i]); break;
98      case 'H': setfield(L,t,"H",argv[++i]); break;
99+     case 'w':
100+      working_directory = argv[++i];
101+      setfield(L,t,"w",argv[i]);
102+      break;
103+     case 's':
104+      lua_source = argv[++i];
105+      setfield(L,t,"s",argv[i]);
106+      break;
107      case 'S': setfield(L,t,"S",""); break;
108      case '1': setfield(L,t,"1",""); break;
109      case 'L': setfield(L,t,"L",argv[++i]); break;
[3127]110@@ -145,25 +161,53 @@
[2705]111   }
112   lua_pop(L,1);
113  }
114-/* #define TOLUA_SCRIPT_RUN */
115-#ifndef TOLUA_SCRIPT_RUN
116+
117  {
118-  int tolua_tolua_open (lua_State* L);
119-  tolua_tolua_open(L);
120- }
121+  char path[BUFSIZ];
122+  char file[BUFSIZ];
123+  path[0] = '\0';
124+  file[0] = '\0';
125+
126+  if (strlen(lua_source) > 0 &&
127+      lua_source[0] != '/' &&
128+      lua_source[0] != '\\' &&
129+      strlen(lua_source) > 1 &&
130+      lua_source[1] != ':')
131+  {
132+   /* Relative path, prefix working directory */
133+   strcpy(path, working_directory);
134+   /* Make sure there is '\\' or '/' at the end of the path */
135+   if (strlen(path) > 0)
136+   {
137+    char last = path[strlen(path) - 1];
138+    if (last != '\\' && last != '/')
139+     strcat(path, "/");
140+   }
141+  }
142+
143+  strcat(path, lua_source);
144+
145+  /* Extract the full path */
146+  {
147+   char* p;
148+   p = strrchr(path, '/');
149+   if (p == NULL)
150+    p = strrchr(path, '\\');
151+   p = (p == NULL) ? path : p + 1;
152+   strcpy(file, p);
153+   *p = '\0';
154+  }
155+  if (strlen(file) == 0)
156+   strcpy(file, "all.lua");
157+
158+  lua_pushstring(L, path);
159+  lua_setglobal(L, "path");
160+  strcat(path, file);
161+#ifdef LUA_VERSION_NUM /* lua 5.1 */
162+  luaL_dofile(L, path);
163 #else
164- {
165-  char* p;
166-  char  path[BUFSIZ];
167-  strcpy(path,argv[0]);
168-  p = strrchr(path,'/');
169-  if (p==NULL) p = strrchr(path,'\\');
170-  p = (p==NULL) ? path : p+1;
171-  sprintf(p,"%s","../src/bin/lua/");
172-  lua_pushstring(L,path); lua_setglobal(L,"path");
173-               strcat(path,"all.lua");
174-  lua_dofile(L,path);
175- }
176+  lua_dofile(L, path);
177 #endif
178+ }
179  return 0;
180 }
Note: See TracBrowser for help on using the repository browser.