- uint32_t cmd = 0;
- size_t ms_timeout = -1;
-
- //Check number of arguments
- int n = lua_gettop(L);
- if(n == 0)
- {
- //signal error by returning Nil, errorstring
- lua_pushnil(L);
- lua_pushstring(L,"You need to supply at least command to wait for");
- return 2; // two return values
- }
- if(n >= 1)
- {
- //pop cmd
- cmd = luaL_checkunsigned(L,1);
- }
- if(n >= 2)
- {
- //Did the user send a timeout ?
- //Check if the current top of stack is an integer
- ms_timeout = luaL_checkunsigned(L,2);
- //printf("Timeout set to %dms\n" , (int) ms_timeout);
- }
-
- UsbCommand response;
-
- if(WaitForResponseTimeout(cmd, &response, ms_timeout))
- {
- //Push it as a string
- lua_pushlstring(L,(const char *)&response,sizeof(UsbCommand));
-
- return 1;// return 1 to signal one return value
- }else{
- //Push a Nil instead
- lua_pushnil(L);
- return 1;// one return value
- }
+ uint32_t cmd = 0;
+ size_t ms_timeout = -1;
+
+ //Check number of arguments
+ int n = lua_gettop(L);
+ if(n == 0)
+ {
+ //signal error by returning Nil, errorstring
+ lua_pushnil(L);
+ lua_pushstring(L,"You need to supply at least command to wait for");
+ return 2; // two return values
+ }
+ if(n >= 1)
+ {
+ //pop cmd
+ cmd = luaL_checkunsigned(L,1);
+ }
+ if(n >= 2)
+ {
+ //Did the user send a timeout ?
+ //Check if the current top of stack is an integer
+ ms_timeout = luaL_checkunsigned(L,2);
+ //printf("Timeout set to %dms\n" , (int) ms_timeout);
+ }
+
+ UsbCommand response;
+
+ if(WaitForResponseTimeout(cmd, &response, ms_timeout))
+ {
+ //Push it as a string
+ lua_pushlstring(L,(const char *)&response,sizeof(UsbCommand));
+
+ return 1;// return 1 to signal one return value
+ }else{
+ //Push a Nil instead
+ lua_pushnil(L);
+ return 1;// one return value
+ }