@@ -73,20 +73,41 @@ lAcpiEvaluateObject(lua_State *L)
7373 return luaL_error (L , "Incorrect arguments" );
7474 }
7575
76+ /*
77+ * 4 is expected to be a table of ACPI_OBJECTs.
78+ * These are passed when the method you are evaluating needs them.
79+ * Each element of this table is converted into an ACPI_OBJECT.
80+ *
81+ * Each element of this table must be a table with:
82+ * 1: obj_type -- UINT32 specifying the current element's
83+ * ACPI_OBJECT_TYPE
84+ * 2..n: fields -- used to build the corresponding
85+ * ACPI_OBJECT, where n depends on obj_type. (see actypes.h)
86+ *
87+ */
7688 if (lua_istable (L , 4 )) {
7789 obj_count = lua_rawlen (L , 4 );
7890 objs = malloc (sizeof (ACPI_OBJECT ) * obj_count );
7991 if (objs == NULL ) {
80- return luaL_error (L , "Failed to malloc objs." );
92+ lua_pushnil (L );
93+ lua_pushstring (L , "Failed to malloc objs." );
94+ return 2 ;
8195 }
8296
8397 for (int i = 0 ; i < obj_count ; ++ i ) {
8498 lua_rawgeti (L , 4 , i + 1 );
85-
8699 lua_getfield (L , -1 , "obj_type" );
87- obj_type = lua_int_to_uint32 (L , -1 ,
88- "Invalid ACPI Object type" );
100+
101+ if ((status = lua_int_to_uint32 (L , -1 , & obj_type ))
102+ != AE_OK ) {
103+ lua_pushnil (L );
104+ lua_pushstring (L , "ACPI_OBJECT_TYPE must be"
105+ " UINT32" );
106+ free (objs );
107+ return 2 ;
108+ }
89109 lua_pop (L , 1 );
110+
90111 build_acpi_obj (L , & objs [i ], obj_type );
91112 lua_pop (L , 1 );
92113 }
@@ -106,8 +127,12 @@ lAcpiEvaluateObject(lua_State *L)
106127
107128 free_acpi_objs (objs , obj_count );
108129
109- return luaL_error (L ,
130+ char errbuf [64 ];
131+ snprintf (errbuf , sizeof (errbuf ),
110132 "AcpiEvaluateObject failed with status 0x%x" , status );
133+ lua_pushnil (L );
134+ lua_pushstring (L , errbuf );
135+ return 2 ;
111136 }
112137
113138 if (return_buffer .Pointer != NULL ) {
0 commit comments