Skip to content

Commit 2150828

Browse files
att
1 parent 4af8747 commit 2150828

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed

src/LuaCEmbed/table/table/getters/index/fdeclare.index.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ double LuaCEmbedTable_get_double_by_index(LuaCEmbedTable *self, int index);
2424

2525
char * LuaCEmbedTable_get_string_by_index(LuaCEmbedTable *self, int index);
2626

27-
bool LuaCEmbedTable_get_bool_by_index(LuaCEmbedTable *self, int index);
28-
27+
char * LuaCEmbedTable_get_raw_string_by_index(LuaCEmbedTable *self, int index, long *size);
2928

29+
bool LuaCEmbedTable_get_bool_by_index(LuaCEmbedTable *self, int index);

src/LuaCEmbed/table/table/getters/index/fdefine.index.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,44 @@ char * LuaCEmbedTable_get_string_by_index(LuaCEmbedTable *self, int index){
243243
return NULL;
244244
}
245245

246+
char * LuaCEmbedTable_get_raw_string_by_index(LuaCEmbedTable *self, int index, long *size){
247+
PRIVATE_LUA_CEMBED_TABLE_PROTECT_NULL
248+
249+
int formatted_index = index + LUA_CEMBED_INDEX_DIF;
250+
251+
lua_getglobal(self->main_object->state,self->global_name);
252+
int table_index = lua_gettop(self->main_object->state);
253+
long converted_index = privateLuaCEmbedTable_convert_index(self,formatted_index);
254+
int total = 1;
255+
lua_pushnil(self->main_object->state);
256+
while(lua_next(self->main_object->state,table_index)){
257+
if(total == converted_index){
258+
if(privateLuaCEmbedTable_ensure_type_with_index(self,converted_index,LUA_CEMBED_STRING)){
259+
lua_pop(self->main_object->state,1);
260+
PRIVATE_LUA_CEMBED_TABLE_CLEAR_STACK
261+
return NULL;
262+
}
263+
char * result = (char*)lua_tolstring(self->main_object->state,-1,(size_t*)size);
264+
lua_pop(self->main_object->state,1);
265+
PRIVATE_LUA_CEMBED_TABLE_CLEAR_STACK
266+
return result;
267+
}
268+
lua_pop(self->main_object->state,1);
269+
total+=1;
270+
271+
}
272+
273+
privateLuaCEmbed_raise_error_not_jumping(
274+
self->main_object,
275+
PRIVATE_LUA_CEMBED_WRONG_TYPE_INDEX,
276+
index,
277+
self->global_name,
278+
LuaCembed_convert_arg_code(LUA_CEMBED_NIL),
279+
LuaCembed_convert_arg_code(LUA_CEMBED_STRING)
280+
);
281+
PRIVATE_LUA_CEMBED_TABLE_CLEAR_STACK
282+
return NULL;
283+
}
246284
bool LuaCEmbedTable_get_bool_by_index(LuaCEmbedTable *self, int index){
247285
PRIVATE_LUA_CEMBED_TABLE_PROTECT_BOOL
248286

@@ -279,4 +317,4 @@ bool LuaCEmbedTable_get_bool_by_index(LuaCEmbedTable *self, int index){
279317
);
280318
PRIVATE_LUA_CEMBED_TABLE_CLEAR_STACK
281319
return LUA_CEMBED_GENERIC_ERROR;
282-
}
320+
}

src/LuaCEmbed/table/table/getters/keys/fdeclare.keys.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
char* LuaCembedTable_get_string_prop(LuaCEmbedTable *self, const char *name);
1010

11+
char* LuaCembedTable_get_raw_string_prop(LuaCEmbedTable *self, const char *name,long *size);
12+
1113
long long LuaCembedTable_get_long_prop(LuaCEmbedTable *self, const char *name);
1214

1315
double LuaCembedTable_get_double_prop(LuaCEmbedTable *self, const char *name);

src/LuaCEmbed/table/table/getters/keys/fdefine.keys.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//silver_chain_scope_start
33
//mannaged by silver chain
44
#include "../../../../../imports/imports.fdeclare.h"
5+
#include <cstddef>
56
//silver_chain_scope_end
67

78
int LuaCEmbedTable_get_type_prop(LuaCEmbedTable *self, const char *name){
@@ -28,6 +29,19 @@ char* LuaCembedTable_get_string_prop(LuaCEmbedTable *self , const char *name){
2829
return value;
2930
}
3031

32+
char* LuaCembedTable_get_raw_string_prop(LuaCEmbedTable *self, const char *name,long *size){
33+
PRIVATE_LUA_CEMBED_TABLE_PROTECT_NULL
34+
35+
lua_getglobal(self->main_object->state,self->global_name);
36+
privateLuaCEmbd_get_field_protected(self->main_object,name);
37+
if(privateLuaCEmbedTable_ensure_type_with_key(self, name, LUA_CEMBED_STRING)){
38+
return NULL;
39+
}
40+
41+
char *value = (char*)lua_tolstring(self->main_object->state,-1,(size_t*)size);
42+
PRIVATE_LUA_CEMBED_TABLE_CLEAR_STACK
43+
return value;
44+
}
3145

3246
long long LuaCembedTable_get_long_prop(LuaCEmbedTable *self , const char *name){
3347
PRIVATE_LUA_CEMBED_TABLE_PROTECT_NUM

src/namespace/table/fdefine.table.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ LuaCembedTableModule newLuaCembedTableModule(){
3838
self.get_double_prop = LuaCembedTable_get_double_prop;
3939
self.get_long_prop = LuaCembedTable_get_long_prop;
4040
self.get_string_prop = LuaCembedTable_get_string_prop;
41+
self.get_raw_string_prop= LuaCembedTable_get_raw_string_prop;
4142
self.get_type_prop = LuaCEmbedTable_get_type_prop;
4243
self.destroy_prop = LuaCembedTable_destroy_prop;
4344

@@ -58,6 +59,7 @@ LuaCembedTableModule newLuaCembedTableModule(){
5859
self.get_double_by_index = LuaCEmbedTable_get_double_by_index;
5960
self.get_bool_by_index = LuaCEmbedTable_get_bool_by_index;
6061
self.get_string_by_index= LuaCEmbedTable_get_string_by_index;
62+
self.get_raw_string_by_index =LuaCEmbedTable_get_raw_string_by_index;
6163
self.get_sub_table_by_index = LuaCEmbedTable_get_sub_table_by_index;
6264
return self;
6365
}

src/namespace/table/typesC.table.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef struct {
4242
void (*set_bool_prop)(LuaCEmbedTable *self , const char *name, bool value);
4343
int (*get_type_prop)(LuaCEmbedTable *self, const char *name);
4444
char* (*get_string_prop)(LuaCEmbedTable *self , const char *name);
45+
char* (*get_raw_string_prop)(LuaCEmbedTable *self, const char *name,long *size);
4546
long long (*get_long_prop)(LuaCEmbedTable *self , const char *name);
4647
double (*get_double_prop)(LuaCEmbedTable *self , const char *name);
4748
bool (*get_bool_prop)(LuaCEmbedTable *self , const char *name);
@@ -59,6 +60,8 @@ typedef struct {
5960
long long (*get_long_by_index)(LuaCEmbedTable *self, int index);
6061
double (*get_double_by_index)(LuaCEmbedTable *self, int index);
6162
char * (*get_string_by_index)(LuaCEmbedTable *self, int index);
63+
char * (*get_raw_string_by_index)(LuaCEmbedTable *self, int index, long *size);
64+
6265
bool (*get_bool_by_index)(LuaCEmbedTable *self, int index);
6366

6467
}LuaCembedTableModule;

0 commit comments

Comments
 (0)