Lee McColl Sylvester wrote:
Hey list,

I need to perform a conversion from a Neko object to a different vm object instance, but to do so requires knowing what fields an object contains. Is it possible to retrieve an array of field names that I can iterate over to perform the conversion?

Thanks,
Lee




If the hashed names are alright, you can use $objfields(). Otherwise, it just happens that I have such code sitting right here to return an array of strings:

get_field_names = function(object) {
//$objfields returns an array of integers, which are the hashed names of the fields
   var field_list = $objfields(object)
   //Number of fields in the array
   var num_fields = $asize(field_list)
   //Empty array to populate with field names
   var field_names = $amake(num_fields)
//Index variable
   var i = 0

   //Loop over the fields
   while(i < num_fields) {
       //Convert integer field to string and store in array
       field_names[i] = $field(field_list[i])

       i = i + 1
   }

   return field_names
}



-Justin

--
Neko : One VM to run them all
(http://nekovm.org)

Reply via email to