forked from daneos/lutango
implement more command data types
This commit is contained in:
parent
619c05fc0d
commit
ccf52c63ea
@ -6,4 +6,4 @@
|
||||
|
||||
void *lut_getobj(lua_State *L, int idx);
|
||||
|
||||
#endif /* __LUT_OBJECT_H__ */
|
||||
#endif /* __OBJECT_H__ */
|
||||
|
||||
@ -19,3 +19,33 @@ void push_string_table(lua_State* L, std::vector<std::string> v)
|
||||
lua_rawseti(L, -2, i+1);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<bool> pop_bool_table(lua_State* L, int idx)
|
||||
{
|
||||
LUT_LOG(TRACE, "Popping boolean table from stack");
|
||||
std::vector<bool> v;
|
||||
lua_settop(L, idx);
|
||||
for(int i = 1; i <= lua_objlen(L, idx); i++)
|
||||
{
|
||||
lua_rawgeti(L, idx, i);
|
||||
bool vi = lua_toboolean(L, idx+1);
|
||||
v.push_back(vi);
|
||||
lua_settop(L, idx);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
std::vector<std::string> pop_string_table(lua_State* L, int idx)
|
||||
{
|
||||
LUT_LOG(TRACE, "Popping string table from stack");
|
||||
std::vector<std::string> v;
|
||||
lua_settop(L, idx);
|
||||
for(int i = 1; i <= lua_objlen(L, idx); i++)
|
||||
{
|
||||
lua_rawgeti(L, idx, i);
|
||||
std::string vi = luaL_checkstring(L, idx+1);
|
||||
v.push_back(vi);
|
||||
lua_settop(L, idx);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@ -10,6 +10,9 @@
|
||||
void push_bool_table(lua_State* L, std::vector<bool> value);
|
||||
void push_string_table(lua_State* L, std::vector<std::string> value);
|
||||
|
||||
std::vector<bool> pop_bool_table(lua_State* L, int idx);
|
||||
std::vector<std::string> pop_string_table(lua_State* L, int idx);
|
||||
|
||||
// CPP: non-specialized templates must be implemented in header file
|
||||
template<class T>
|
||||
void push_number_table(lua_State* L, std::vector<T> v)
|
||||
@ -29,4 +32,20 @@ T pop_number(lua_State* L, int idx)
|
||||
return (T)luaL_checknumber(L, idx);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::vector<T> pop_number_table(lua_State* L, int idx)
|
||||
{
|
||||
LUT_LOG(TRACE, "Popping number table from stack");
|
||||
std::vector<T> v;
|
||||
lua_settop(L, idx);
|
||||
for(int i = 1; i <= lua_objlen(L, idx); i++)
|
||||
{
|
||||
lua_rawgeti(L, idx, i);
|
||||
T vi = luaL_checknumber(L, idx+1);
|
||||
v.push_back(vi);
|
||||
lua_settop(L, idx);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif /* __STACK_H__ */
|
||||
|
||||
@ -28,7 +28,7 @@ int cmd_wrapper(lua_State* L)
|
||||
|
||||
LUT_LOG(TRACE, "Command: %s in:%d out:%d", name, in_type, out_type);
|
||||
|
||||
Tango::DeviceData in = pack_cmd_data(L, 2, in_type);
|
||||
Tango::DeviceData in = pack_cmd_data(L, 1, in_type);
|
||||
Tango::DeviceData out = udata->dev->command_inout(name, in);
|
||||
unpack_cmd_data(L, out, out_type);
|
||||
return 1;
|
||||
|
||||
@ -190,49 +190,49 @@ Tango::DeviceData pack_cmd_data(lua_State* L, int idx, long type)
|
||||
|
||||
case 1: // bool
|
||||
{
|
||||
bool v = lua_toboolean(L, idx);
|
||||
Tango::DevBoolean v = lua_toboolean(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: // short
|
||||
{
|
||||
short v = pop_number<short>(L, idx);
|
||||
Tango::DevShort v = luaL_checknumber(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 3: // long
|
||||
{
|
||||
long v = pop_number<long>(L, idx);
|
||||
Tango::DevLong v = luaL_checknumber(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 4: // float
|
||||
{
|
||||
float v = pop_number<float>(L, idx);
|
||||
Tango::DevFloat v = luaL_checknumber(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 5: // double
|
||||
{
|
||||
double v = pop_number<double>(L, idx);
|
||||
Tango::DevDouble v = luaL_checknumber(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 6: // ushort
|
||||
{
|
||||
unsigned short v = pop_number<unsigned short>(L, idx);
|
||||
Tango::DevUShort v = luaL_checknumber(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 7: // ulong
|
||||
{
|
||||
unsigned long v = pop_number<unsigned long>(L, idx);
|
||||
Tango::DevULong v = luaL_checknumber(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
@ -246,41 +246,96 @@ Tango::DeviceData pack_cmd_data(lua_State* L, int idx, long type)
|
||||
break;
|
||||
}
|
||||
|
||||
case 10: // short[]
|
||||
{
|
||||
std::vector<Tango::DevShort> v = pop_number_table<Tango::DevShort>(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 11: // long[]
|
||||
{
|
||||
std::vector<Tango::DevLong> v = pop_number_table<Tango::DevLong>(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 12: // float[]
|
||||
{
|
||||
std::vector<Tango::DevFloat> v = pop_number_table<Tango::DevFloat>(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 13: // double[]
|
||||
{
|
||||
std::vector<Tango::DevDouble> v = pop_number_table<Tango::DevDouble>(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 14: // ushort[]
|
||||
{
|
||||
std::vector<Tango::DevUShort> v = pop_number_table<Tango::DevUShort>(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 15: // ulong[]
|
||||
{
|
||||
std::vector<Tango::DevULong> v = pop_number_table<Tango::DevULong>(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 16: // string[]
|
||||
{
|
||||
std::vector<std::string> v = pop_string_table(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 23: // long64
|
||||
{
|
||||
// int64_t v = pop_number<int64_t>(L, idx);
|
||||
// data << v;
|
||||
Tango::DevLong64 v = luaL_checknumber(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 24: // ulong64
|
||||
{
|
||||
// uint64_t v = pop_number<uint64_t>(L, idx);
|
||||
// data << v;
|
||||
Tango::DevULong64 v = luaL_checknumber(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 25: // long64[]
|
||||
{
|
||||
std::vector<Tango::DevLong64> v = pop_number_table<Tango::DevLong64>(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 26: // ulong64[]
|
||||
{
|
||||
std::vector<Tango::DevULong64> v = pop_number_table<Tango::DevULong64>(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
case 27: // int
|
||||
{
|
||||
int v = pop_number<int>(L, idx);
|
||||
int v = luaL_checknumber(L, idx);
|
||||
data << v;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 10: // short[]
|
||||
case 11: // long[]
|
||||
case 12: // float[]
|
||||
case 13: // double[]
|
||||
case 14: // ushort[]
|
||||
case 15: // ulong[]
|
||||
case 16: // string[]
|
||||
case 17: // longstring[] ???
|
||||
case 18: // doublestring[] ???
|
||||
case 19: // DevState
|
||||
case 21: // bool[]
|
||||
case 21: // bool[] - cannot insert std::vector<bool(or DevBoolean)> to DeviceData
|
||||
case 22: // uchar
|
||||
case 25: // long64[]
|
||||
case 26: // ulong64[]
|
||||
case 28: // DevEncoded
|
||||
LUT_LOG(WARNING, "Command input argument type not implemented yet: %d", type);
|
||||
break;
|
||||
|
||||
@ -1,9 +1,63 @@
|
||||
local lut = require "lutango"
|
||||
lut.log:set_log_level(lut.log.level.TRACE)
|
||||
lut.log:set_log_level(lut.log.level.WARNING)
|
||||
|
||||
dp = lut.DeviceProxy(arg[1])
|
||||
dp = lut.DeviceProxy(arg[1] or "sys/tg_test/1")
|
||||
|
||||
print(dp:SwitchStates());
|
||||
print(dp:DevBoolean(true));
|
||||
print(dp:DevBoolean(false));
|
||||
print(dp:DevDouble(9.9));
|
||||
function run_void_cmd(cmd)
|
||||
io.write(cmd.."(): ")
|
||||
print(dp[cmd]())
|
||||
end
|
||||
|
||||
function run_scalar_cmd(cmd, input)
|
||||
io.write(cmd.."("..tostring(input).."): ")
|
||||
print(dp[cmd](input))
|
||||
end
|
||||
|
||||
function run_array_cmd(cmd, input)
|
||||
io.write(cmd.."({")
|
||||
for _,v in ipairs(input) do
|
||||
io.write(v..", ")
|
||||
end
|
||||
io.write("}): ")
|
||||
local r = dp[cmd](input)
|
||||
io.write(tostring(r)..": {")
|
||||
for _,v in ipairs(input) do
|
||||
io.write(v..", ")
|
||||
end
|
||||
print("}")
|
||||
end
|
||||
|
||||
run_void_cmd("State")
|
||||
run_void_cmd("Status")
|
||||
run_void_cmd("SwitchStates")
|
||||
run_void_cmd("DevVoid")
|
||||
|
||||
run_scalar_cmd("DevBoolean", true)
|
||||
run_scalar_cmd("DevBoolean", false)
|
||||
run_scalar_cmd("DevDouble", 88.888)
|
||||
run_scalar_cmd("DevDouble", -88.888)
|
||||
run_scalar_cmd("DevFloat", 8.88)
|
||||
run_scalar_cmd("DevFloat", -8.88)
|
||||
run_scalar_cmd("DevLong", 99112233)
|
||||
run_scalar_cmd("DevLong", -99112233)
|
||||
run_scalar_cmd("DevLong64", 1199228833775566)
|
||||
run_scalar_cmd("DevLong64", -1199228833775566)
|
||||
run_scalar_cmd("DevShort", 101)
|
||||
run_scalar_cmd("DevShort", -101)
|
||||
run_scalar_cmd("DevString", "hello world")
|
||||
run_scalar_cmd("DevULong", 9911223344)
|
||||
run_scalar_cmd("DevULong64", 1199228833775566)
|
||||
run_scalar_cmd("DevUShort", 101)
|
||||
-- run_scalar_cmd("DevVarCharArray", "hello world")
|
||||
|
||||
run_array_cmd("DevVarDoubleArray", {1.1111, -2.2222, 3.3333})
|
||||
-- run_array_cmd("DevVarDoubleStringArray", {???})
|
||||
run_array_cmd("DevVarFloatArray", {1.11, -2.22, 3.33})
|
||||
run_array_cmd("DevVarLong64Array", {11111111111, -22222222222, 33333333333})
|
||||
run_array_cmd("DevVarLongArray", {11111111111, -22222222222, 33333333333})
|
||||
-- run_array_cmd("DevVarLongStringArray", {???})
|
||||
run_array_cmd("DevVarShortArray", {1111, -2222, 3333})
|
||||
run_array_cmd("DevVarStringArray", {"hello", "world", "from", "Lua"})
|
||||
run_array_cmd("DevVarULong64Array", {11111111111, 22222222222, 33333333333})
|
||||
run_array_cmd("DevVarULongArray", {11111111111, 22222222222, 33333333333})
|
||||
run_array_cmd("DevVarUShortArray", {1111, 2222, 3333})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user