Skip to content

Commit 88e12e1

Browse files
t
1 parent 97ea0f7 commit 88e12e1

7 files changed

Lines changed: 64 additions & 41 deletions

File tree

build.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,18 @@ local function test_unit(unit,start_assignature)
5454
local file_path = unit..name..".lua"
5555

5656
print("testing: "..file_path)
57-
local output = io.popen("lua "..file_path,"r"):read()
57+
58+
local output = io.popen("lua "..file_path,"r"):read()
59+
if output then
60+
dtw.write_file(unit.."expected.txt",output)
61+
end
62+
63+
64+
local test_assignature = dtw.generate_sha_from_folder_by_content(SIDE_EFFECT)
65+
--means code generated side effect
66+
if start_assignature ~= dtw.generate_sha_from_folder_by_content(SIDE_EFFECT) then
67+
handle_side_effect(unit,test_assignature)
5868
end
59-
6069

6170

6271
--validate_commad_result(result)
@@ -87,7 +96,7 @@ local function main()
8796

8897
print("compiling")
8998

90-
local code = os.execute("gcc -Wall -shared -fpic -o luaFluidJson/luaFluidJson_lib.so src/main.c")
99+
local code = os.execute("gcc -Wall -shared -fpic -fsanitize=address -o luaFluidJson/luaFluidJson_lib.so src/main.c")
91100
if code == 1 then
92101
return
93102
end

saida.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"b":null,"array":[1,2,3],"a":30,"nome":"mateus"}

src/dependencies/LuaCEmbed.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24096,8 +24096,8 @@ void privateLuaCEmbedTable_free(LuaCEmbedTable *self){
2409624096

2409724097
void privateLuaCEmbedTable_free_setting_nill(LuaCEmbedTable *self){
2409824098

24099-
lua_getglobal(self->main_object->state,self->global_name);
24100-
lua_pushnil(self->main_object->state);
24099+
//lua_getglobal(self->main_object->state,self->global_name);
24100+
// lua_pushnil(self->main_object->state);
2410124101
privateLuaCEmbedTable_free(self);
2410224102
}
2410324103

@@ -24211,10 +24211,10 @@ bool LuaCembedTable_has_key_at_index(LuaCEmbedTable *self, long index){
2421124211
lua_pushnil(self->main_object->state);
2421224212
while(lua_next(self->main_object->state,table_index)){
2421324213
if(total == converted_index){
24214-
if(lua_type(self->main_object->state,-2) != LUA_CEMBED_STRING ){
24215-
return false;
24216-
}
24217-
return true;
24214+
24215+
bool has_key =lua_type(self->main_object->state,-2) == LUA_CEMBED_STRING;
24216+
lua_pop(self->main_object->state,1);
24217+
return has_key;
2421824218
}
2421924219

2422024220
lua_pop(self->main_object->state,1);

src/dump/dump.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ cJSON * lua_fluid_json_dump_to_cJSON_object(LuaCEmbedTable *table){
6262

6363
}
6464
if(type == lua.types.BOOL){
65-
bool value = lua.tables.get_bool_by_index(table,i);
65+
bool value = lua.tables.get_bool_by_index(table,i);;
6666
cJSON_AddBoolToObject(created_object,key, value);
6767
}
68+
6869
if(type == lua.types.TABLE){
6970
LuaCEmbedTable *internal = lua.tables.get_sub_table_by_index(table,i);
7071
cJSON *value = lua_fluid_json_dump_table_to_cJSON(internal);
@@ -78,6 +79,7 @@ cJSON * lua_fluid_json_dump_to_cJSON_object(LuaCEmbedTable *table){
7879
cJSON * lua_fluid_json_dump_table_to_cJSON(LuaCEmbedTable *table){
7980

8081
if(lua_json_fluid_table_is_object(table)){
82+
8183
return lua_fluid_json_dump_to_cJSON_object(table);
8284
}
8385
return lua_fluid_json_dump_to_cJSON_array(table);
@@ -117,9 +119,10 @@ LuaCEmbedResponse * lua_fluid_json_dump_to_string(LuaCEmbed *args){
117119

118120
bool ident = true;
119121

120-
if(lua.args.get_type(args,1) != lua.types.NOT_FOUND){
122+
if(lua.args.get_type(args,1) != lua.types.NILL){
121123
ident = lua.args.get_bool(args,1);
122124
}
125+
123126
if(lua.has_errors(args)){
124127
char *error_msg = lua.get_error_message(args);
125128
return lua.response.send_error(error_msg);
@@ -135,28 +138,13 @@ LuaCEmbedResponse * lua_fluid_json_dump_to_string(LuaCEmbed *args){
135138

136139
LuaCEmbedResponse *response = lua.response.send_str(result_str);
137140
cJSON_Delete(result);
138-
139141
free(result_str);
140142
return response;
141143
}
142144

143145

144146
LuaCEmbedResponse * lua_fluid_json_dump_to_file(LuaCEmbed *args){
145147

146-
char * output = lua.args.get_str(args,1);
147-
if(lua.has_errors(args)){
148-
char *error_msg = lua.get_error_message(args);
149-
return lua.response.send_error(error_msg);
150-
}
151-
bool ident = true;
152-
153-
if(lua.args.get_type(args,2) != lua.types.NOT_FOUND){
154-
ident = lua.args.get_bool(args,2);
155-
}
156-
if(lua.has_errors(args)){
157-
char *error_msg = lua.get_error_message(args);
158-
return lua.response.send_error(error_msg);
159-
}
160148

161149
cJSON *result = NULL;
162150
int element_type = lua.args.get_type(args,0);
@@ -186,6 +174,25 @@ LuaCEmbedResponse * lua_fluid_json_dump_to_file(LuaCEmbed *args){
186174
);
187175
}
188176

177+
178+
char * output = lua.args.get_str(args,1);
179+
if(lua.has_errors(args)){
180+
char *error_msg = lua.get_error_message(args);
181+
cJSON_Delete(result);
182+
return lua.response.send_error(error_msg);
183+
}
184+
bool ident = true;
185+
186+
if(lua.args.get_type(args,2) != lua.types.NILL){
187+
ident = lua.args.get_bool(args,2);
188+
}
189+
190+
if(lua.has_errors(args)){
191+
char *error_msg = lua.get_error_message(args);
192+
cJSON_Delete(result);
193+
return lua.response.send_error(error_msg);
194+
}
195+
189196
char *result_str = NULL;
190197
if(ident){
191198
result_str = cJSON_Print(result);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"sons": [{
3-
"maried": null,
4-
"name": "son1"
5-
}],
62
"name": "Nateus",
73
"age": 27,
4+
"sons": [{
5+
"name": "son1",
6+
"maried": null
7+
}],
88
"maried": false
99
}

test/main_test/dump_to_string/dump_to_string.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ local user ={
44

55
name='Nateus',
66
age=27,
7-
maried=false,
87
sons={
9-
{name='son1',maried='null'}
8+
{name='son1',maried=true }
109
}
1110
}
1211
local ident = true
13-
local dumped = json.dumps_to_string(user,ident);
14-
print(dumped)
12+
local value = json.dumps_to_string(user,ident);
13+
14+
print(value)
15+

teste.lua

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11

22
json = require("luaFluidJson/luaFluidJson")
33

4-
local teste = {
5-
a =30,
6-
b= 'null',
7-
c=function()end,
8-
nome='mateus',
9-
array = {1,2,3}
4+
local user ={
5+
6+
name='Nateus',
7+
sss=true,
8+
9+
age=27.4,
10+
sons={
11+
{name='son1',maried=true }
12+
}
1013
}
14+
local ident = true
15+
local value = json.dumps_to_string(user,ident);
16+
print(value)
1117

12-
json.dumps_to_file(teste,"saida.json",false)

0 commit comments

Comments
 (0)