Skip to content

Commit d41d2d8

Browse files
att
1 parent 68c7580 commit d41d2d8

File tree

6 files changed

+90
-40
lines changed

6 files changed

+90
-40
lines changed

LuaCembed.h

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,12 @@ double private_lua_embed_floor(double x) {
701701
#include <string.h>
702702
#include <time.h>
703703

704+
#ifdef _WIN32
705+
#include <windows.h>
706+
#else
707+
#include <unistd.h>
708+
#include <fcntl.h>
709+
#endif
704710

705711

706712
#define LUA_CORE
@@ -23917,19 +23923,38 @@ static int os_rename (lua_State *L) {
2391723923
const char *toname = luaL_checkstring(L, 2);
2391823924
return luaL_fileresult(L, rename(fromname, toname) == 0, NULL);
2391923925
}
23926+
#ifdef __linux
23927+
static int os_tmpname(lua_State *L) {
23928+
char buff[100];
23929+
const char *tmpdir = "/tmp/lua_XXXXXX";
23930+
int fd = mkstemp(buff);
23931+
if (fd == -1) {
23932+
return luaL_error(L, "unable to generate a unique filename");
23933+
}
2392023934

23935+
close(fd);
23936+
lua_pushstring(L, buff);
23937+
return 1;
23938+
}
23939+
#endif
23940+
#ifdef _WIN32
2392123941

23922-
static int os_tmpname (lua_State *L) {
23923-
char buff[LUA_TMPNAMBUFSIZE];
23924-
int err;
23925-
lua_tmpnam(buff, err);
23926-
if (l_unlikely(err))
23942+
static int os_tmpname(lua_State *L) {
23943+
char buff[100] = {0};
23944+
const char *template = "lua_XXXXXX";
23945+
23946+
GetTempPathA(sizeof(buff), buff);
23947+
23948+
UINT fd = GetTempFileNameA(buff, template, 0, buff);
23949+
if (fd == -1) {
2392723950
return luaL_error(L, "unable to generate a unique filename");
23951+
}
23952+
close(fd);
23953+
// Empurrar o nome do arquivo temporário para a pilha Lua
2392823954
lua_pushstring(L, buff);
2392923955
return 1;
2393023956
}
23931-
23932-
23957+
#endif
2393323958
static int os_getenv (lua_State *L) {
2393423959
lua_pushstring(L, getenv(luaL_checkstring(L, 1)));
2393523960
return 1;

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,15 +1486,15 @@ type string
14861486
value: indexable random string
14871487
------------------------------------------
14881488
index: 1
1489-
key: name
1490-
type string
1491-
value: Mateus
1492-
------------------------------------------
1493-
index: 2
14941489
key: age
14951490
type number
14961491
value: 27.000000
14971492
------------------------------------------
1493+
index: 2
1494+
key: name
1495+
type string
1496+
value: Mateus
1497+
------------------------------------------
14981498
index: 3
14991499
key: single
15001500
type boolean

output_test

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
==21903== Memcheck, a memory error detector
2-
==21903== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
3-
==21903== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
4-
==21903== Command: ./tests/main_test/table_handle/T_setting_sub_table/exec.out
5-
==21903== Parent PID: 21293
6-
==21903==
7-
==21903==
8-
==21903== HEAP SUMMARY:
9-
==21903== in use at exit: 0 bytes in 0 blocks
10-
==21903== total heap usage: 143 allocs, 143 frees, 12,949 bytes allocated
11-
==21903==
12-
==21903== All heap blocks were freed -- no leaks are possible
13-
==21903==
14-
==21903== For lists of detected and suppressed errors, rerun with: -s
15-
==21903== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
1+
==28218== Memcheck, a memory error detector
2+
==28218== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
3+
==28218== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
4+
==28218== Command: ./tests/main_test/table_handle/T_setting_sub_table/exec.out
5+
==28218== Parent PID: 27294
6+
==28218==
7+
==28218==
8+
==28218== HEAP SUMMARY:
9+
==28218== in use at exit: 0 bytes in 0 blocks
10+
==28218== total heap usage: 143 allocs, 143 frees, 12,949 bytes allocated
11+
==28218==
12+
==28218== All heap blocks were freed -- no leaks are possible
13+
==28218==
14+
==28218== For lists of detected and suppressed errors, rerun with: -s
15+
==28218== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

src/dependencies/lua/loslib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static int os_rename (lua_State *L) {
166166
}
167167
#ifdef __linux
168168
static int os_tmpname(lua_State *L) {
169-
char buff[LUA_TMPNAMBUFSIZE];
169+
char buff[100];
170170
const char *tmpdir = "/tmp/lua_XXXXXX";
171171
int fd = mkstemp(buff);
172172
if (fd == -1) {

tests/LuaCEmbed.h

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,12 @@ double private_lua_embed_floor(double x) {
701701
#include <string.h>
702702
#include <time.h>
703703

704+
#ifdef _WIN32
705+
#include <windows.h>
706+
#else
707+
#include <unistd.h>
708+
#include <fcntl.h>
709+
#endif
704710

705711

706712
#define LUA_CORE
@@ -23917,19 +23923,38 @@ static int os_rename (lua_State *L) {
2391723923
const char *toname = luaL_checkstring(L, 2);
2391823924
return luaL_fileresult(L, rename(fromname, toname) == 0, NULL);
2391923925
}
23926+
#ifdef __linux
23927+
static int os_tmpname(lua_State *L) {
23928+
char buff[100];
23929+
const char *tmpdir = "/tmp/lua_XXXXXX";
23930+
int fd = mkstemp(buff);
23931+
if (fd == -1) {
23932+
return luaL_error(L, "unable to generate a unique filename");
23933+
}
2392023934

23935+
close(fd);
23936+
lua_pushstring(L, buff);
23937+
return 1;
23938+
}
23939+
#endif
23940+
#ifdef _WIN32
2392123941

23922-
static int os_tmpname (lua_State *L) {
23923-
char buff[LUA_TMPNAMBUFSIZE];
23924-
int err;
23925-
lua_tmpnam(buff, err);
23926-
if (l_unlikely(err))
23942+
static int os_tmpname(lua_State *L) {
23943+
char buff[100] = {0};
23944+
const char *template = "lua_XXXXXX";
23945+
23946+
GetTempPathA(sizeof(buff), buff);
23947+
23948+
UINT fd = GetTempFileNameA(buff, template, 0, buff);
23949+
if (fd == -1) {
2392723950
return luaL_error(L, "unable to generate a unique filename");
23951+
}
23952+
close(fd);
23953+
// Empurrar o nome do arquivo temporário para a pilha Lua
2392823954
lua_pushstring(L, buff);
2392923955
return 1;
2393023956
}
23931-
23932-
23957+
#endif
2393323958
static int os_getenv (lua_State *L) {
2393423959
lua_pushstring(L, getenv(luaL_checkstring(L, 1)));
2393523960
return 1;

tests/main_test/table_handle/S_iterating_over_table/expected.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ type string
44
value: indexable random string
55
------------------------------------------
66
index: 1
7-
key: name
8-
type string
9-
value: Mateus
10-
------------------------------------------
11-
index: 2
127
key: age
138
type number
149
value: 27.000000
1510
------------------------------------------
11+
index: 2
12+
key: name
13+
type string
14+
value: Mateus
15+
------------------------------------------
1616
index: 3
1717
key: single
1818
type boolean

0 commit comments

Comments
 (0)