335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
# File 'lib/relisp/type_conversion/programming_types.rb', line 335
def self.from_elisp(object)
slave = object[:slave]
object_variable = slave.get_permanent_variable(object[:variable])
unless slave.elisp_eval("(type-of #{object_variable})") == "hash-table".to_sym
raise ArgumentError, "#{object_variable} isn't a hash-table"
end
keys_var = slave.new_elisp_variable
vals_var = slave.new_elisp_variable
slave.elisp_exec( "(setq #{keys_var} nil)" )
slave.elisp_exec( "(setq #{vals_var} nil)" )
slave.elisp_exec( "(maphash (lambda (key val)
(setq #{keys_var} (append #{keys_var} (list key)))
(setq #{vals_var} (append #{vals_var} (list val)))) #{object_variable})" )
keys = slave.elisp_eval( keys_var )
vals = slave.elisp_eval( vals_var )
keys ||= nil
keys = keys.to_list
vals = vals.to_list
hash = Hash.new
keys.each_index do |i|
hash[keys[i]] = vals[i]
end
slave.makunbound(object_variable)
slave.makunbound(keys_var)
slave.makunbound(vals_var)
return hash
end
|