diff --git a/libraries/AP_Scripting/generator/src/main.c b/libraries/AP_Scripting/generator/src/main.c index 401518febf..07857df845 100644 --- a/libraries/AP_Scripting/generator/src/main.c +++ b/libraries/AP_Scripting/generator/src/main.c @@ -1642,9 +1642,11 @@ void emit_field(const struct userdata_field *field, const char* object_name, con case TYPE_INT32_T: case TYPE_UINT8_T: case TYPE_UINT16_T: - case TYPE_ENUM: fprintf(source, "%slua_pushinteger(L, %s%s%s%s);\n", indent, object_name, object_access, field->name, index_string); break; + case TYPE_ENUM: + fprintf(source, "%slua_pushinteger(L, static_cast(%s%s%s%s));\n", indent, object_name, object_access, field->name, index_string); + break; case TYPE_UINT32_T: fprintf(source, "%snew_uint32_t(L);\n", indent); fprintf(source, "%s*static_cast(luaL_checkudata(L, -1, \"uint32_t\")) = %s%s%s%s;\n", indent, object_name, object_access, field->name, index_string); @@ -1659,7 +1661,9 @@ void emit_field(const struct userdata_field *field, const char* object_name, con fprintf(source, "%slua_pushstring(L, %s%s%s%s);\n", indent, object_name, object_access, field->name, index_string); break; case TYPE_USERDATA: - error(ERROR_USERDATA, "Userdata does not currently support access to userdata field's"); + // userdatas must allocate a new container to return + fprintf(source, "%snew_%s(L);\n", indent, field->type.data.ud.sanatized_name); + fprintf(source, "%s*check_%s(L, -1) = %s%s%s%s;\n", indent, field->type.data.ud.sanatized_name, object_name, object_access, field->name, index_string); break; case TYPE_AP_OBJECT: // FIXME: collapse the identical cases here, and use the type string function error(ERROR_USERDATA, "AP_Object does not currently support access to userdata field's");