Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/kicklib/src/external/tolua/changes_orxonox.diff @ 7944

Last change on this file since 7944 was 7941, checked in by rgrieder, 14 years ago

Kicked CEGUILua from our repository and adjusted the build system accordingly.
The Linux part is still missing though.

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