1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/**
* \file path_translate.c
* \brief Translates between path separators.
* \author Copyright (c) 2002-2013 Jason Perkins and the Premake project
*/
#include "premake.h"
#include <string.h>
void do_translate(char* value, const char sep)
{
char* ch;
for (ch = value; *ch != '\0'; ++ch) {
if (*ch == '/' || *ch == '\\') {
*ch = sep;
}
}
}
static void translate(char* result, const char* value, const char sep)
{
strcpy(result, value);
do_translate(result, sep);
}
int path_translate(lua_State* L)
{
const char* sep;
char buffer[0x4000];
if (lua_gettop(L) == 1) {
sep = "\\";
}
else {
sep = luaL_checkstring(L, 2);
}
if (lua_istable(L, 1)) {
int i = 0;
lua_newtable(L);
lua_pushnil(L);
while (lua_next(L, 1)) {
const char* value = luaL_checkstring(L, 4);
translate(buffer, value, sep[0]);
lua_pop(L, 1);
lua_pushstring(L, buffer);
lua_rawseti(L, -3, ++i);
}
return 1;
}
else {
const char* value = luaL_checkstring(L, 1);
translate(buffer, value, sep[0]);
lua_pushstring(L, buffer);
return 1;
}
}
|