Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/external/tolua/changes_orxonox.diff @ 7209

Last change on this file since 7209 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

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