Skip to content

Commit cec9ca7

Browse files
authored
suport Projection([ConfigList| string of table]) , proj:load([ConfigList| string of table] (#368)
* improve Projection() and load(), add args ([ ConfigList | string[,string,...] ]) Signed-off-by: Shewer Lu <shewer@gmail.com> * fixed core dumped error for load(string, ...) nonstring of nil bool userdata userdata Signed-off-by: Shewer Lu <shewer@gmail.com> * suport Projection([ConfigList| string of table]) , proj:load([ConfigList| string of table]) Signed-off-by: shewer <shewer@gmail.com> * suport Projection([ConfigList| string of table]) , proj:load([ConfigList| string of table]) Signed-off-by: shewer <shewer@gmail.com> --------- Signed-off-by: Shewer Lu <shewer@gmail.com> Signed-off-by: shewer <shewer@gmail.com>
1 parent 77b0968 commit cec9ca7

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

src/types.cc

+34-5
Original file line numberDiff line numberDiff line change
@@ -1183,9 +1183,38 @@ an<R> Get(an<T> t) {
11831183
}
11841184

11851185
namespace ProjectionReg{
1186-
using T = Projection;
1187-
an<T> make(){
1188-
return New<T>();
1186+
typedef Projection T;
1187+
1188+
int raw_load(lua_State *L) {
1189+
C_State C;
1190+
bool res =false;
1191+
an<T> t = LuaType<an<T>>::todata(L,1);
1192+
if (lua_isuserdata(L, 2)) {
1193+
res = t->Load(LuaType<an<ConfigList>>::todata(L, 2));
1194+
}
1195+
else if (lua_istable(L, 2)){
1196+
auto cl = New<ConfigList>();
1197+
for ( auto &str : LuaType<vector<string>>::todata(L, 2, &C)) {
1198+
cl->Append(New<ConfigValue>(str));
1199+
}
1200+
res = t->Load(cl);
1201+
}
1202+
else {
1203+
1204+
}
1205+
lua_pushboolean(L, res);
1206+
return 1;
1207+
}
1208+
1209+
int raw_make(lua_State *L) {
1210+
auto t = New<T>();
1211+
if ( 1 <= lua_gettop(L)) {
1212+
LuaType<an<T>>::pushdata(L, t);
1213+
lua_insert(L, 1);
1214+
raw_load(L);
1215+
}
1216+
LuaType<an<T>>::pushdata(L, t);
1217+
return 1;
11891218
}
11901219

11911220
int raw_apply(lua_State* L) {
@@ -1200,12 +1229,12 @@ namespace ProjectionReg{
12001229
}
12011230

12021231
static const luaL_Reg funcs[] = {
1203-
{"Projection",WRAP(make)},
1232+
{"Projection",raw_make},
12041233
{ NULL, NULL },
12051234
};
12061235

12071236
static const luaL_Reg methods[] = {
1208-
{"load",WRAPMEM(T::Load)},
1237+
{"load", raw_load},
12091238
{"apply", raw_apply},
12101239
{ NULL, NULL },
12111240
};

0 commit comments

Comments
 (0)