Skip to content

Commit c18b3e7

Browse files
adding setopt
1 parent e47db23 commit c18b3e7

File tree

8 files changed

+199
-31
lines changed

8 files changed

+199
-31
lines changed

LuaCEmbed.h

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23746,6 +23746,7 @@ int private_LuaCEmbed_ensure_top_stack_arg_type(LuaCEmbed *self, int index,int a
2374623746

2374723747
int privateLuaCEmbed_put_arg_on_top(LuaCEmbed *self, int index){
2374823748
long formatted_index = index + LUA_CEMBED_INDEX_DIF;
23749+
2374923750
char *formated_arg = private_LuaCembed_format(PRIVATE_LUA_CEMBED_ARGS,formatted_index-1);
2375023751
lua_getglobal(self->state,formated_arg);
2375123752

@@ -23756,7 +23757,6 @@ int privateLuaCEmbed_put_arg_on_top(LuaCEmbed *self, int index){
2375623757
privateLuaCEmbed_raise_error_not_jumping(self,error);
2375723758
free(error);
2375823759
free(formated_arg);
23759-
2376023760
return LUA_CEMBED_GENERIC_ERROR;
2376123761
}
2376223762
free(formated_arg);
@@ -23771,51 +23771,71 @@ int LuaCEmbed_get_total_args(LuaCEmbed *self){
2377123771

2377223772
int LuaCEmbed_get_arg_type(LuaCEmbed *self,int index){
2377323773
PRIVATE_LUA_CEMBED_PROTECT_NUM
23774+
2377423775
privateLuaCEmbed_put_arg_on_top(self,index);
23775-
return lua_type(self->state, -1);
23776+
23777+
int type = lua_type(self->state, -1);
23778+
lua_settop(self->state,0);
23779+
return type;
2377623780
}
2377723781

2377823782

2377923783
long long LuaCEmbed_get_long_arg(LuaCEmbed *self, int index){
2378023784
PRIVATE_LUA_CEMBED_PROTECT_NUM
23785+
2378123786
privateLuaCEmbed_put_arg_on_top(self,index);
2378223787
if(private_LuaCEmbed_ensure_top_stack_arg_type(self,index,LUA_CEMBED_NUMBER)){
23788+
lua_settop(self->state,0);
2378323789
return (long )LUA_CEMBED_NOT_FOUND;
2378423790
}
23785-
return (long long)lua_tonumber(self->state,-1);
23791+
long long result = (long long)lua_tonumber(self->state,-1);
23792+
lua_settop(self->state,0);
23793+
return result;
2378623794
}
2378723795

2378823796

2378923797
double LuaCEmbed_get_double_arg(LuaCEmbed *self, int index){
2379023798
PRIVATE_LUA_CEMBED_PROTECT_NUM
23799+
2379123800
privateLuaCEmbed_put_arg_on_top(self,index);
2379223801
if(private_LuaCEmbed_ensure_top_stack_arg_type(self,index,LUA_CEMBED_NUMBER)){
23802+
lua_settop(self->state,0);
2379323803
return (long )LUA_CEMBED_NOT_FOUND;
2379423804
}
23795-
return lua_tonumber(self->state,-1);
23805+
double result = lua_tonumber(self->state,-1);
23806+
lua_settop(self->state,0);
23807+
return result;
2379623808
}
2379723809

2379823810
bool LuaCEmbed_get_bool_arg(LuaCEmbed *self, int index){
2379923811
PRIVATE_LUA_CEMBED_PROTECT_BOOL
23812+
2380023813
privateLuaCEmbed_put_arg_on_top(self,index);
2380123814
if(private_LuaCEmbed_ensure_top_stack_arg_type(self,index,LUA_CEMBED_BOOL)){
23815+
lua_settop(self->state,0);
2380223816
return (long )LUA_CEMBED_NOT_FOUND;
2380323817
}
23804-
return lua_toboolean(self->state,-1);
23818+
bool result = lua_toboolean(self->state,-1);
23819+
lua_settop(self->state,0);
23820+
return result;
2380523821
}
2380623822

2380723823

2380823824
char * LuaCEmbed_get_str_arg(LuaCEmbed *self, int index){
2380923825
PRIVATE_LUA_CEMBED_PROTECT_NULL
23826+
lua_settop(self->state,0);
2381023827
privateLuaCEmbed_put_arg_on_top(self,index);
2381123828
if(private_LuaCEmbed_ensure_top_stack_arg_type(self,index,LUA_CEMBED_STRING)){
2381223829
return NULL;
2381323830
}
23814-
return (char*)lua_tostring(self->state,-1);
23831+
char *result = (char*)lua_tostring(self->state,-1);
23832+
lua_settop(self->state,0);
23833+
return result;
2381523834
}
2381623835

2381723836
LuaCEmbedTable * LuaCEmbed_get_arg_table(LuaCEmbed *self,int index){
2381823837
PRIVATE_LUA_CEMBED_PROTECT_NULL
23838+
2381923839
privateLuaCEmbed_put_arg_on_top(self,index);
2382023840
if(private_LuaCEmbed_ensure_top_stack_arg_type(self,index,LUA_CEMBED_TABLE)){
2382123841
return NULL;
@@ -23825,7 +23845,9 @@ LuaCEmbedTable * LuaCEmbed_get_arg_table(LuaCEmbed *self,int index){
2382523845
char *formated_arg = private_LuaCembed_format(PRIVATE_LUA_CEMBED_ARGS,formatted_index-1);
2382623846
LuaCEmbedTable *created = LuaCembed_get_global_table(self,formated_arg);
2382723847
free(formated_arg);
23848+
lua_settop(self->state,0);
2382823849
return created;
23850+
2382923851
}
2383023852

2383123853
LuaCEmbedTable* LuaCEmbed_run_args_lambda(LuaCEmbed *self, int index, LuaCEmbedTable *args_to_call, int total_returns){
@@ -23836,12 +23858,14 @@ LuaCEmbedTable* LuaCEmbed_run_args_lambda(LuaCEmbed *self, int index, LuaCEmbedT
2383623858
privateLuaCEmbed_put_arg_on_top(self,index);
2383723859
if(private_LuaCEmbed_ensure_top_stack_arg_type(self,index,LUA_CEMBED_FUNCTION)){
2383823860
free(formatted_arg);
23861+
lua_settop(self->state,0);
2383923862
return NULL;
2384023863
}
2384123864
int total_args = private_lua_cEmbed_unpack(args_to_call,formatted_arg);
2384223865
if(lua_pcall(self->state,total_args,total_returns,0)){
2384323866
privateLuaCEmbed_raise_error_not_jumping(self, lua_tostring(self->state,-1));
2384423867
free(formatted_arg);
23868+
lua_settop(self->state,0);
2384523869
return NULL;
2384623870
}
2384723871

@@ -23864,6 +23888,7 @@ LuaCEmbedTable* LuaCEmbed_run_args_lambda(LuaCEmbed *self, int index, LuaCEmbedT
2386423888
}
2386523889

2386623890
free(formatted_arg);
23891+
lua_settop(self->state,0);
2386723892
return result;
2386823893

2386923894
}
@@ -24095,8 +24120,6 @@ void privateLuaCEmbedTable_free(LuaCEmbedTable *self){
2409524120
}
2409624121

2409724122
void privateLuaCEmbedTable_free_setting_nill(LuaCEmbedTable *self){
24098-
24099-
lua_getglobal(self->main_object->state,self->global_name);
2410024123
lua_pushnil(self->main_object->state);
2410124124
lua_setglobal(self->main_object->state,self->global_name);
2410224125
privateLuaCEmbedTable_free(self);
@@ -24122,7 +24145,7 @@ long LuaCEmbedTable_get_full_size(LuaCEmbedTable *self){
2412224145
// printf("%s\n", LuaCembed_convert_arg_code(lua_type(self->main_object->state,-1)));
2412324146
lua_pop(self->main_object->state,1);
2412424147
}
24125-
24148+
lua_settop(self->main_object->state,0);
2412624149
return total;
2412724150
}
2412824151

@@ -24201,6 +24224,7 @@ char *LuaCembedTable_get_key_by_index(LuaCEmbedTable *self, long index){
2420124224
}
2420224225
bool LuaCembedTable_has_key_at_index(LuaCEmbedTable *self, long index){
2420324226
PRIVATE_LUA_CEMBED_TABLE_PROTECT_BOOL
24227+
lua_settop(self->main_object->state,0);
2420424228
private_lua_cembed_memory_limit = self->main_object->memory_limit;
2420524229

2420624230
long formatted_index = index + LUA_CEMBED_INDEX_DIF;
@@ -24214,17 +24238,23 @@ bool LuaCembedTable_has_key_at_index(LuaCEmbedTable *self, long index){
2421424238
if(total == converted_index){
2421524239
bool has_key =lua_type(self->main_object->state,-2) == LUA_CEMBED_STRING;
2421624240
lua_pop(self->main_object->state,1);
24241+
lua_settop(self->main_object->state,0);
24242+
2421724243
return has_key;
2421824244
}
2421924245

2422024246
lua_pop(self->main_object->state,1);
2422124247
total+=1;
2422224248
}
24249+
lua_settop(self->main_object->state,0);
24250+
2422324251
return false;
2422424252
}
2422524253

2422624254
long long LuaCEmbedTable_get_long_by_index(LuaCEmbedTable *self, int index){
2422724255
PRIVATE_LUA_CEMBED_TABLE_PROTECT_NUM
24256+
lua_settop(self->main_object->state,0);
24257+
2422824258
private_lua_cembed_memory_limit = self->main_object->memory_limit;
2422924259
int formatted_index = index + LUA_CEMBED_INDEX_DIF;
2423024260

@@ -24238,6 +24268,8 @@ long long LuaCEmbedTable_get_long_by_index(LuaCEmbedTable *self, int index){
2423824268
if(total == converted_index){
2423924269
if(privateLuaCEmbedTable_ensure_type_with_index(self,converted_index,LUA_CEMBED_NUMBER)){
2424024270
lua_pop(self->main_object->state,1);
24271+
lua_settop(self->main_object->state,0);
24272+
2424124273
return LUA_CEMBED_GENERIC_ERROR;
2424224274
}
2424324275
long result = (long)lua_tonumber(self->main_object->state,-1);
@@ -24248,6 +24280,7 @@ long long LuaCEmbedTable_get_long_by_index(LuaCEmbedTable *self, int index){
2424824280
total+=1;
2424924281

2425024282
}
24283+
lua_settop(self->main_object->state,0);
2425124284

2425224285
privateLuaCEmbed_raise_error_not_jumping(
2425324286
self->main_object,
@@ -24275,6 +24308,8 @@ double LuaCEmbedTable_get_double_by_index(LuaCEmbedTable *self, int index){
2427524308
if(total == converted_index){
2427624309
if(privateLuaCEmbedTable_ensure_type_with_index(self,converted_index,LUA_CEMBED_NUMBER)){
2427724310
lua_pop(self->main_object->state,1);
24311+
lua_settop(self->main_object->state,0);
24312+
2427824313
return LUA_CEMBED_GENERIC_ERROR;
2427924314
}
2428024315
double result = (double )lua_tonumber(self->main_object->state,-1);
@@ -24285,6 +24320,7 @@ double LuaCEmbedTable_get_double_by_index(LuaCEmbedTable *self, int index){
2428524320
total+=1;
2428624321

2428724322
}
24323+
lua_settop(self->main_object->state,0);
2428824324

2428924325
privateLuaCEmbed_raise_error_not_jumping(
2429024326
self->main_object,
@@ -24312,6 +24348,8 @@ char * LuaCEmbedTable_get_string_by_index(LuaCEmbedTable *self, int index){
2431224348
if(total == converted_index){
2431324349
if(privateLuaCEmbedTable_ensure_type_with_index(self,converted_index,LUA_CEMBED_STRING)){
2431424350
lua_pop(self->main_object->state,1);
24351+
lua_settop(self->main_object->state,0);
24352+
2431524353
return NULL;
2431624354
}
2431724355
char * result = (char*)lua_tostring(self->main_object->state,-1);
@@ -24322,6 +24360,7 @@ char * LuaCEmbedTable_get_string_by_index(LuaCEmbedTable *self, int index){
2432224360
total+=1;
2432324361

2432424362
}
24363+
lua_settop(self->main_object->state,0);
2432524364

2432624365
privateLuaCEmbed_raise_error_not_jumping(
2432724366
self->main_object,
@@ -24348,6 +24387,8 @@ bool LuaCEmbedTable_get_bool_by_index(LuaCEmbedTable *self, int index){
2434824387
if(total == converted_index){
2434924388
if(privateLuaCEmbedTable_ensure_type_with_index(self,converted_index,LUA_CEMBED_BOOL)){
2435024389
lua_pop(self->main_object->state,1);
24390+
lua_settop(self->main_object->state,0);
24391+
2435124392
return LUA_CEMBED_GENERIC_ERROR;
2435224393
}
2435324394
bool result = lua_toboolean(self->main_object->state,-1);
@@ -24358,6 +24399,7 @@ bool LuaCEmbedTable_get_bool_by_index(LuaCEmbedTable *self, int index){
2435824399
total+=1;
2435924400

2436024401
}
24402+
lua_settop(self->main_object->state,0);
2436124403

2436224404
privateLuaCEmbed_raise_error_not_jumping(
2436324405
self->main_object,
@@ -24373,6 +24415,8 @@ bool LuaCEmbedTable_get_bool_by_index(LuaCEmbedTable *self, int index){
2437324415

2437424416
int LuaCEmbedTable_get_type_prop(LuaCEmbedTable *self, const char *name){
2437524417
PRIVATE_LUA_CEMBED_TABLE_PROTECT_NUM
24418+
lua_settop(self->main_object->state,0);
24419+
2437624420
private_lua_cembed_memory_limit = self->main_object->memory_limit;
2437724421

2437824422
lua_getglobal(self->main_object->state,self->global_name);
@@ -24382,6 +24426,8 @@ int LuaCEmbedTable_get_type_prop(LuaCEmbedTable *self, const char *name){
2438224426

2438324427
char* LuaCembedTable_get_string_prop(LuaCEmbedTable *self , const char *name){
2438424428
PRIVATE_LUA_CEMBED_TABLE_PROTECT_NULL
24429+
lua_settop(self->main_object->state,0);
24430+
2438524431
private_lua_cembed_memory_limit = self->main_object->memory_limit;
2438624432

2438724433
lua_getglobal(self->main_object->state,self->global_name);
@@ -24395,6 +24441,8 @@ char* LuaCembedTable_get_string_prop(LuaCEmbedTable *self , const char *name){
2439524441

2439624442
long long LuaCembedTable_get_long_prop(LuaCEmbedTable *self , const char *name){
2439724443
PRIVATE_LUA_CEMBED_TABLE_PROTECT_NUM
24444+
lua_settop(self->main_object->state,0);
24445+
2439824446
private_lua_cembed_memory_limit = self->main_object->memory_limit;
2439924447

2440024448
lua_getglobal(self->main_object->state,self->global_name);
@@ -24407,6 +24455,8 @@ long long LuaCembedTable_get_long_prop(LuaCEmbedTable *self , const char *name
2440724455

2440824456
double LuaCembedTable_get_double_prop(LuaCEmbedTable *self , const char *name){
2440924457
PRIVATE_LUA_CEMBED_TABLE_PROTECT_NUM
24458+
lua_settop(self->main_object->state,0);
24459+
2441024460
private_lua_cembed_memory_limit = self->main_object->memory_limit;
2441124461

2441224462
lua_getglobal(self->main_object->state,self->global_name);
@@ -24419,6 +24469,8 @@ double LuaCembedTable_get_double_prop(LuaCEmbedTable *self , const char *name){
2441924469

2442024470
bool LuaCembedTable_get_bool_prop(LuaCEmbedTable *self , const char *name){
2442124471
PRIVATE_LUA_CEMBED_TABLE_PROTECT_BOOL
24472+
lua_settop(self->main_object->state,0);
24473+
2442224474
private_lua_cembed_memory_limit = self->main_object->memory_limit;
2442324475

2442424476
lua_getglobal(self->main_object->state,self->global_name);

main

0 Bytes
Binary file not shown.

main.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,34 @@
22
LuaCEmbedNamespace lua_n;
33

44

5-
LuaCEmbedResponse * hello(LuaCEmbed *args){
6-
printf("hello world");
5+
LuaCEmbedResponse * add_func(LuaCEmbed *args){
6+
7+
8+
double num1 = lua_n.args.get_long_arg_clojure_evalation(args,0,"function(t) return t.num1 end ");
9+
double num2 = lua_n.args.get_long_arg_clojure_evalation(args,0,"function(t) return t.num2 end ");
10+
11+
if(lua_n.has_errors(args)){
12+
char *error_message = lua_n.get_error_message(args);
13+
return lua_n.response.send_error(error_message);
14+
}
15+
return lua_n.response.send_double(num1+num2);
716
return NULL;
817
}
918

1019
int main(int argc, char *argv[]){
1120

1221
lua_n = newLuaCEmbedNamespace();
1322
LuaCEmbed * l = lua_n.newLuaEvaluation();
14-
lua_n.add_callback(l,"hello",hello);
23+
lua_n.add_callback(l,"add",add_func);
24+
1525

16-
lua_n.evaluete_file(l,"tests/target/hello.lua");
26+
double result = lua_n.get_evaluation_double(l,"add({num1=10, num2=30})");
1727

1828
if(lua_n.has_errors(l)){
1929
printf("error: %s\n",lua_n.get_error_message(l));
2030
}
31+
printf("resullt :%lf\n",result);
32+
2133
lua_n.free(l);
2234

2335
return 0;

0 commit comments

Comments
 (0)